home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-25 | 166.0 KB | 5,995 lines | [TEXT/MPS ] |
- {[d-,h-,k+,o=100,q+,r+,rec+,t=2,u+,:+,j=15/20/25/30/35/40/45/50/57/1$]} {Pasmat opts!}
-
- UNIT SVAppleEvents;
-
- (*
- SVAppleEvents.p
-
- Version 3.0d8
-
- Copyright © SRL Data 1992, 1993
-
- All rights reserved
-
- Produced by : SRL Data
- Originally Developed for UK.DTS
-
- *)
-
- { New for 3.0d1 :
- Recommenting of many functions to improve clarity.
- Implementation of nearly all menu commands via Apple Events.
- Page Setup on each window (with visible page breaks)
- Show Borders on each window with bug fixes in display.
-
- New for 3.0d2 :
- 19-Feb-92 : NH : Implement printing
- Fix drawing on scrollbar on show page breaks
- Make IssueAEOpenDoc a function (for printing)
- Make Paste Styled
-
- 21-Feb-92 : NH : Use new (in SVEditions.p) calls for updating section info.
-
- 27-Feb-92 : NH : SendTextMessage zapped and other routines used solely by it.
-
-
- 5-Mar-92 : NH : Added HandleCreatePub, IssueCreatePub
- 18-Mar-92 : NH : Zap PoseMessageDialog & mod AdornDefault
- 27-Mar-92 : NH : Call AssocAllSections when saved
-
- Start of updating to constants in Winter AERegistry.
-
- 3-Jun-92 : NH : Check for AEInteraction allowed before printing.
-
- New for 3.0d3 :
-
- 16-Jun-92 : NH : Continue updating to match latest registry.
- typeText gone - now typeChar
- classes of kAECut etc. changed (see registry)
- Added pIsModified code.
- 17-Jun-92 : NH : Modify HandleSetData - Use AEResolve to yield tokenDescriptor, then
- extract appropriate token data.
- 18-Jun-92 : NH : Tidy up
- Fix AEDescs being left after send of events
- Ensure SendAESetObjProp zaps all supplied params - now VAR params
- Zap AEDescs left behind in HandleGetData.
- 26-Jun-92 : NH : Zap AddNamedStyleItem, AddNamedStyleItem, BuildStyleDescList
- Add code for typeTextStyles as per registry.
- DoOpenDocument fixed to cope with no files in list etc.
- Fixed buggy cast of windowToken to DPtr in DoCloseWindow
- HandleShowSelection modified to take textTokens and WindowTokens
- Fix sizeof in MakeSelfAddress.
- 25-Jun-92 : NH : StyleToName zapped
-
- Changes for 3.0d4 :
-
- 3-Jul-92 : NH : Fix SetWindowProperty typeMyText
- 7-Jul-92 : NH : Add missing window props - pIsFloating, pHasCloseBox, pIsZoomable
- 13-Jul-92 : NH : Complete the menu classes.
- Allow -ve absolute positions - i.e. last line of ...
- Change Line access to allow relative offsets
- 14-Jul-92 : NH : Change region massages for window positions (thanks huggy!)
- 15-Jul-92 : NH : Modified HandleGetData/SetData to allow styledText and typeChar
- Recording of keyStrokes
- 17-Jul-92 : NH : Enter key -> compile text - filtered out too
- Fix setting of styles so that styles not in on/off styles untouched
- 5-Aug-92 : NH : Add pUserSelection
- Zap cSelection
- Added MakeSelectedTextObject for Gustav
- Styles made to match behaviour in Inside Mac VI
- Fixed setting of styles to match registry
- Fixed saving to work after name change of window
- Mark document as dirty after SetData
- Feed back all filing errors
- Moved some data from descriptor procedures to SVEditAEUtils.c
-
- Changes for 3.0d5:
-
- 10-Aug-92 : NH : Fixed Quit save no - AEInteractWithUser called now
- Added IssueQuitCommand.
- Install cLine from typeMyText accessor
- Changes for 3.0d6:
-
- 10-Sep-92 : JL : Fixed gTypingBuffer- this was not initialised in the Pascal
- version, although it was in C.
- Added check for gRecordingImplemented when sending text just for
- recording.
- Changes for 3.0d7:
-
- 16-Nov-92 : JL : Changed pUserSelection to pSelection
- }
-
- {
- This file includes :
-
- a) the code for the AppleEvent initialisation
- b) the routines for all the Edition Manager events
- c) the Apple® Event Object Support
- }
-
- INTERFACE
-
- USES
- MemTypes,
- QuickDraw,
- Packages,
- GestaltEqu,
-
- AppleEvents,
- AEObjects,
- AEPackObject,
- Editions,
- Printing,
- Menus,
-
- SVEditGlobals,
- SVEditUtils,
- SVEditFile,
- SVEditWindow,
- SVEditions;
-
- PROCEDURE InitAppleEvents;
- PROCEDURE DoAppleEvent(theEvent : EventRecord);
-
- (*
- Text Commands
- *)
- PROCEDURE IssueCutCommand(theDocument:DPtr);
- PROCEDURE IssueCopyCommand(theDocument:DPtr);
- PROCEDURE IssuePasteCommand(theDocument:DPtr);
- PROCEDURE IssueClearCommand(theDocument:DPtr);
- PROCEDURE IssueFontCommand(theDocument:DPtr;theItem:INTEGER);
- PROCEDURE IssueSizeCommand(theDocument:DPtr;theItem:INTEGER);
- PROCEDURE IssueStyleCommand(theDocument:DPtr;theItem:INTEGER);
-
- (*
- Window Commands
- *)
-
- PROCEDURE IssueZoomCommand(whichWindow:WindowPtr; whichPart:INTEGER);
- PROCEDURE IssueCloseCommand(whichWindow:WindowPtr);
- PROCEDURE IssueSizeWindow(whichWindow:WindowPtr; newHSize:INTEGER; newVSize:INTEGER);
- PROCEDURE IssueMoveWindow(whichWindow:windowPtr; sizeRect:Rect);
- PROCEDURE IssuePageSetupWindow(whichWindow:windowPtr; thePageSetup:TPrint);
- PROCEDURE IssueShowBorders(whichWindow:windowPtr; showBorders:BOOLEAN);
- PROCEDURE IssuePrintWindow(whichWindow:windowPtr);
-
- (*
- Document Commands
- *)
-
- FUNCTION IssueAEOpenDoc(myFSSpec: FSSpec):OSErr;
- PROCEDURE IssueAENewWindow;
- FUNCTION IssueSaveCommand(theWindow : WindowPtr;
- where : FSSpecPtr):OSErr;
-
- FUNCTION IssueRevertCommand(theWindow : WindowPtr):OSErr;
- FUNCTION IssueQuitCommand:OSErr;
-
- PROCEDURE IssueCreatePublisher(whichDoc:DPtr);
-
- (*
- Recording of Keystrokes
- *)
-
- PROCEDURE AddKeyToTypingBuffer(theDocument : DPtr; theKey :char);
-
- PROCEDURE FlushAndRecordTypingBuffer;
-
- IMPLEMENTATION
-
- USES
- Fonts,
- Scrap,
- SysEqu,
- AERegistry,
- SVEditAEUtils;
-
- CONST
-
- { these should come from the registry }
-
- kAEStartedRecording = 'rec1';
- kAEStoppedRecording = 'rec0';
-
-
- pText = 'TEXT';
- cSpot = 'cspt';
-
- (*
- Text Properties
- *)
-
- pStringWidth = 'pwid';
-
- (*
- Window Properties - See the Registry for Details
- *)
-
- pPosition = 'ppos';
-
- pPageSetup = 'PSET'; (* One of ours - Not in registry *)
- pShowBorders = 'PBOR'; (* Another of ours *)
-
- typeTPrint = 'TPNT'; (* A raw TPrint record - also one of ours *)
-
- (*
- Error Codes
- *)
-
- kAEGenericErr = -1799;
-
- TYPE typingBuffer = PACKED ARRAY[0..31999] OF CHAR;
- typingBufPtr = ^typingBuffer;
-
- VAR gBigBrother : INTEGER; (* Count of Scripting Systems recording us *)
- gTypingBuffer : typingBufPtr;
- gCharsInBuffer : INTEGER;
- gTypingTargetObject : AEDesc;
-
- {-----------------------------------------------------------------------}
- {*---------- APPLE EVENT HANDLING ---------------*}
- {-----------------------------------------------------------------------}
-
- {$S Main}
-
- {*-----------------------------------------------------------------------
- Utility Routines for getting data from AEDesc's
- -----------------------------------------------------------------------*}
-
- FUNCTION GetTHPrintFromDescriptor(sourceDesc : AEDesc;
- VAR result : THPrint):OSErr;
- VAR myErr : OSErr;
- ignoreErr : OSErr;
- ptSize : Size;
- resultDesc : AEDesc;
-
- BEGIN
- myErr := AECoerceDesc(sourceDesc,typeTPrint,resultDesc);
-
- result := NIL;
-
- IF (myErr=noErr) THEN
- BEGIN
- result := THPrint(NewHandle(SizeOf(TPrint)));
-
- PrOpen;
- PrintDefault(result);
-
- HLock(Handle(result));
-
- GetRawDataFromDescriptor(resultDesc,
- @result^^,
- sizeof(TPrint),
- ptSize);
-
- HUnLock(Handle(result));
-
- IF (ptSize<sizeof(TPrint)) OR
- (PrValidate(result)) THEN
- BEGIN
- myErr := errAECoercionFail;
- DisposHandle(Handle(result));
- result := NIL;
- END;
-
- PrClose;
- END;
-
- IF (resultDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(resultDesc);
-
- GetTHPrintFromDescriptor := myErr;
- END; (*GetTHPrintFromDescriptor*)
-
-
- {*****************************************************************************}
- {
- Object Accessors - Utility Routines
- }
-
- {$S ObjectAccessors}
-
- FUNCTION WindowNameToWindowPtr(nameStr: StringPtr): WindowPtr;
- {
- Returns the WindowPtr of the window with title nameStr
- or NIL if there is no matching window.
- }
- VAR theWindow : WindowPtr;
- windTitle : Str255;
-
- BEGIN
- WindowNameToWindowPtr := NIL;
- theWindow := WindowPtr(Handle(WindowList)^);
- {
- iterate through windows - we use WindowList 'cos we could
- have made the window invisible and then we lose it - so we
- can't set it back to visible!!
- }
- WHILE theWindow <> NIL DO
- BEGIN
- GetWTitle(theWindow,windTitle);
- IF EqualString(windTitle,nameStr^,FALSE,TRUE) THEN { ignore case, don't ignore diacriticals }
- BEGIN
- WindowNameToWindowPtr := theWindow;
- EXIT(WindowNameToWindowPtr);
- END;
- theWindow := WindowPtr(WindowPeek(theWindow)^.nextWindow);
- END;
- END; { WindowNameToWindowPtr }
-
- FUNCTION GetWindowPtrOfNthWindow(index: INTEGER): WindowPtr;
- { returns a ptr to the window with the given index
- (front window is 1, behind that is 2, etc.). If
- there's no window with that index (inc. no windows
- at all), returns NIL.
- }
- VAR theWindow : WindowPtr;
-
- BEGIN
- GetWindowPtrOfNthWindow := NIL;
- theWindow := WindowPtr(Handle(WindowList)^);
-
- { iterate through windows }
-
- WHILE (theWindow <> NIL) DO
- BEGIN
- index := index-1;
- IF (index <= 0) THEN
- BEGIN
- GetWindowPtrOfNthWindow := theWindow;
- EXIT(GetWindowPtrOfNthWindow);
- END;
-
- theWindow := WindowPtr(WindowPeek(theWindow)^.nextWindow);
- END;
- END; { GetWindowPtrOfNthWindow }
-
- FUNCTION CountWindows:INTEGER;
- VAR theWindow : WindowPtr;
- index : INTEGER;
-
- BEGIN
- index := 0;
- theWindow := WindowPtr(Handle(WindowList)^);
-
- { iterate through windows }
-
- WHILE (theWindow <> NIL) DO
- BEGIN
- index := index+1;
- theWindow := WindowPtr(WindowPeek(theWindow)^.nextWindow);
- END;
-
- CountWindows := index;
-
- END; (*CountWindows*)
-
- FUNCTION ItemForNamedFont(theName:Str255):INTEGER;
- VAR itemName : Str255;
- limit : INTEGER;
-
- BEGIN
- ItemForNamedFont := 0;
- limit := CountMItems(myMenus[fontM]);
- WHILE (limit>0) DO
- BEGIN
- GetItem(myMenus[fontM],limit,itemName);
- IF IUEqualString(theName, itemName)=0 THEN
- BEGIN
- ItemForNamedFont := limit;
- limit:=0;
- END
- ELSE
- limit := limit-1;
- END;
- END; (*ItemForNamedFont*)
-
- {*-----------------------------------------------------------------------
- Name: DoOpenApp
- Purpose: Called on startup, creates a new document.
- -----------------------------------------------------------------------*}
-
- {$S Main}
- FUNCTION DoOpenApp( message, reply: AppleEvent; refcon: LONGINT ): OSErr;
- VAR ourDoc : DPtr;
-
- BEGIN
- {just create a new document}
- ourDoc := NewDocument(false);
-
- IF ourDoc<>NIL THEN
- BEGIN
- ShowWindow(ourDoc^.theWindow);
- DoOpenApp := noErr
- END
- ELSE
- DoOpenApp := -108;
- END;
-
- {*-----------------------------------------------------------------------
- Name: DoOpenDocument
- Purpose: Open all the documents passed in the Open AppleEvent.
- -----------------------------------------------------------------------*}
-
- {$S Main}
- FUNCTION DoOpenDocument( message, reply: AppleEvent; refcon: LONGINT ): OSErr;
- VAR
- index,
- itemsInList : LONGINT;
- keywd : AEKeyWord;
- err : OSErr;
- ignoreErr : OSErr;
- docList : AEDescList;
- actSize : LONGINT;
- typeCode : DescType;
- theFSSpec : FSSpec;
-
-
- BEGIN
- {open the specified documents}
-
- docList.dataHandle := NIL;
-
- err := AEGetParamDesc(message, keyDirectObject, typeAEList, docList) ;
- IF (err=noErr) THEN
- err := AECountItems( docList, itemsInList)
- ELSE
- itemsInList := 0;
-
- FOR index := 1 TO itemsInList DO
- IF (err=noErr) THEN
- BEGIN
- err := AEGetNthPtr( docList,
- index,
- typeFSS,
- keywd,
- typeCode,
- @theFSSpec,
- sizeof(theFSSpec),
- actSize);
- IF (err=noErr) THEN
- err := OpenOld(theFSSpec);
- END;
-
- IF (docList.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(docList);
-
- DoOpenDocument := err;
- END;
-
- {*-----------------------------------------------------------------------
- Name: MyQuit
- Purpose: Quit event received- exit the program.
- -----------------------------------------------------------------------*}
-
- {$S Main}
- FUNCTION MyQuit(message : AppleEvent;reply : AppleEvent;refcon:LONGINT): OSErr;
- VAR
- saveOpt : DescType;
- tempErr : OSErr;
- myErr : OSErr;
- returnedType : DescType;
- actSize : LONGINT;
-
- BEGIN
- saveOpt := kAEAsk; (* the default *)
- tempErr := AEGetParamPtr(message,
- keyAESaveOptions,
- typeEnumerated,
- returnedType,
- Ptr(@saveOpt),
- sizeof(saveOpt),
- actSize);
-
- IF (saveOpt <> kAENo) THEN
- myErr := AEInteractWithUser(kAEDefaultTimeout, nil, nil);
-
- IF (myErr = noErr) THEN
- DoQuit(saveOpt);
-
- myQuit := myErr;
- END;
-
- {*-----------------------------------------------------------------------
- Name: DoAppleEvent
- Purpose: Process and despatch the AppleEvent
- -----------------------------------------------------------------------*}
-
- {$S Main}
- PROCEDURE DoAppleEvent(theEvent : EventRecord);
-
- VAR err: OsErr;
-
- BEGIN
- {should check for your own event message types here - if you have any}
-
- err := AEProcessAppleEvent(theEvent);
- END;
-
- {*-----------------------------------------------------------------------
- Name: MakeSelfAddress
- Purpose: Builds an AEAddressDesc for the current process
- -----------------------------------------------------------------------*}
-
- FUNCTION MakeSelfAddress(VAR selfAddress : AEAddressDesc) : OSErr;
-
- VAR
- procSerNum : ProcessSerialNumber;
-
- BEGIN
- procSerNum.highLongOfPSN := 0;
- procSerNum.lowLongOfPSN := kCurrentProcess;
-
- MakeSelfAddress := AECreateDesc(typeProcessSerialNumber,
- Ptr(@procSerNum),
- sizeof(procSerNum),
- selfAddress);
-
- END; (* MakeSelfAddress *)
-
- {*--------------------------------------------------------------------
- Name : SendAESetObjProp
- Function : Creates a property object from an object,
- a property type and its data and sends it to
- the requested address, and cleans up zapping params too
- --------------------------------------------------------------------*}
-
- FUNCTION SendAESetObjProp(VAR theObj : AEDesc;
- theProp : DescType;
- VAR theData : AEDesc;
- VAR toWhom : AEAddressDesc):OSErr;
-
- VAR propObjSpec : AEDesc;
- myAppleEvent : AppleEvent;
- defReply : AppleEvent;
- myErr : OSErr;
- ignoreErr : OSErr;
- theProperty : AEDesc;
-
- BEGIN
- { create an object spec that represents the property of the given object }
-
- myErr := AECreateDesc(typeType,
- @theProp,
- sizeof(theProp),
- theProperty);
-
- IF (myErr=noErr) THEN
- myErr:= CreateObjSpecifier(cProperty,
- theObj,
- formPropertyID,
- theProperty,
- TRUE,
- propObjSpec);
-
- { create event }
-
- IF (myErr=noErr) THEN
- myErr := AECreateAppleEvent(kAECoreSuite,
- kAESetData,
- toWhom,
- 0,
- 0,
- myAppleEvent);
-
- { add prop obj spec to the event }
-
- IF (myErr=noErr) THEN
- myErr := AEPutParamDesc(myAppleEvent,keyDirectObject,propObjSpec);
-
- { add prop data to the event }
-
- IF (myErr=noErr) THEN
- myErr := AEPutParamDesc(myAppleEvent,keyAEData,theData);
-
- { send event }
-
- IF (myErr=noErr) THEN
- myErr := AESend(myAppleEvent,
- defReply,
- kAENoReply+kAEAlwaysInteract,
- kAENormalPriority,
- kAEDefaultTimeOut,
- NIL,
- NIL);
-
- ignoreErr := AEDisposeDesc(myAppleEvent);
-
- ignoreErr := AEDisposeDesc(propObjSpec);
-
- ignoreErr := AEDisposeDesc(theData);
-
- ignoreErr := AEDisposeDesc(toWhom);
-
- SendAESetObjProp := myErr;
-
- END; { SendAESetObjProp }
-
- {----------------------------------------------------------------------------------------------}
- {
- Private AEObject definitions
- }
- {$S AECommandHandlers}
-
- CONST
- typeMyAppl = 'BAPP'; { sig of my private token type for the app - appToken }
- typeMyWndw = 'BWIN'; { sig of my private token type for windows - windowToken }
- typeMyText = 'BTXT'; { sig of my private token type for text - textToken }
- typeMyTextProp = 'BPRP'; { sig of my private token type for text properties - textPropToken }
- typeMyWindowProp = 'WPRP'; { sig of my private token type for window properties - windowPropToken }
- typeMyApplProp = 'APRP'; { sig of my private token type for appl properties - applPropToken }
- typeMyMenu = 'MTKN'; { sig of my private token type for menus - menuToken }
- typeMyMenuItem = 'ITKN'; { sig of my private token type for menus - menuItemToken }
- typeMyMenuProp = 'MPRP'; { sig of my private token type for menu properties - menuPropToken }
- typeMyItemProp = 'IPRP'; { sig of my private token type for menu item properties - menuItemPropToken }
-
- TYPE
- (* These are entirely private to our app - used only when resolving the object specifier *)
-
- appToken = ProcessSerialNumber;
-
- applPropToken = RECORD
- tokenApplToken : appToken;
- tokenApplProperty : DescType;
- END;
-
- windowToken = WindowPtr;
-
- windowPropToken = RECORD
- tokenWindowToken : WindowToken;
- tokenProperty : DescType;
- END;
-
- textToken = RECORD
- tokenWindow : WindowPtr;
- tokenOffset : INTEGER;
- tokenLength : INTEGER;
- END;
-
- textPropToken = RECORD
- propertyTextToken : textToken;
- propertyProperty : DescType;
- END;
-
- (* Tokens related to menus *)
-
- MenuToken = RECORD
- theTokenMenu : MenuHandle;
- theTokenID : INTEGER;
- END;
-
- MenuItemToken = RECORD
- theMenuToken : MenuToken;
- theTokenItem : INTEGER;
- END;
-
- MenuPropToken = RECORD
- theMenuToken : MenuToken;
- theMenuProp : DescType;
- END;
-
- MenuItemPropToken = RECORD
- theItemToken : MenuItemToken;
- theItemProp : DescType;
- END;
-
- FUNCTION GotRequiredParams(theAppleEvent: AppleEvent): OSErr;
- VAR myErr : OSErr;
- returnedType: DescType;
- actSize : Size;
-
- BEGIN
- { look for the keyMissedKeywordAttr, just to see if it's there }
-
- myErr := AEGetAttributePtr( theAppleEvent,
- keyMissedKeywordAttr,
- typeWildCard,
- returnedType,
- NIL,
- 0,
- actSize);
-
- IF myErr = errAEDescNotFound THEN
- GotRequiredParams := noErr { attribute not there means we got all req params }
- ELSE
- IF myErr = noErr THEN
- GotRequiredParams := errAEParamMissed { attribute there means missed at least one }
- ELSE
- GotRequiredParams := myErr; { some unexpected arror in looking for the attribute }
- END; (* GotReqiredParams *)
-
- {*--------------------------------------------------------------------
- Name : SetSelectionOfAppleEventDirectObject
- Function : Resolves the Direct Object into a text token and
- sets the selection of the specified document to that
- specified in the direct object.
- Returns the doc and TEHandle chosen.
- --------------------------------------------------------------------*}
-
- FUNCTION SetSelectionOfAppleEventDirectObject(theAppleEvent : AppleEvent;
- VAR theDocument : DPtr;
- VAR theHTE : TEHandle):OsErr;
- VAR myErr : OSErr;
- returnedType : DescType;
- actSize : longInt;
- myTextToken : TextToken;
- paramErr : OSErr;
-
- BEGIN
- SetSelectionOfAppleEventDirectObject := noErr;
-
- paramErr := AEGetParamPtr(theAppleEvent,
- keyDirectObject,
- typeMyText,
- returnedType,
- @myTextToken,
- SizeOf(myTextToken),
- actSize);
-
- myErr := GotRequiredParams(theAppleEvent);
-
- { now let's work on the direct object, if any }
-
- IF (paramErr = errAEDescNotFound) THEN
- BEGIN
- { no direct object; check we have a window }
- IF (FrontWindow = NIL) THEN
- BEGIN
- SetSelectionOfAppleEventDirectObject := -1700;
- Exit(SetSelectionOfAppleEventDirectObject);
- END;
- theDocument := DPtrFromWindowPtr(FrontWindow);
- theHTE := theDocument^.theText;
- END;
-
- IF (paramErr = noErr) THEN
- BEGIN
- { got a text token }
-
- theDocument := DPtrFromWindowPtr(myTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- TESetSelect(myTextToken.tokenOffset-1,
- myTextToken.tokenOffset+myTextToken.tokenLength-1,
- theHTE);
-
- END;
-
- IF (paramErr<>noErr) AND
- (paramErr<>errAEDescNotFound) THEN
- BEGIN
- theDocument := DPtrFromWindowPtr(FrontWindow);
- theHTE := theDocument^.theText;
- END;
-
- SetSelectionOfAppleEventDirectObject := myErr;
-
- END; (* SetSelectionOfAppleEventDirectObject *)
-
- {*--------------------------------------------------------------------
- Name : SetSelectionOfAppleEventDirectObject
- Function : Resolves the whatObject type of the AppleEvent into a text
- token and sets the selection to be that specified in the
- text token.
- Returns the doc and TEHandle chosen.
- --------------------------------------------------------------------*}
-
- FUNCTION SetSelectionOfAppleEventObject(whatObject : OSType;
- theAppleEvent : AppleEvent;
- VAR theDocument : DPtr;
- VAR theHTE : TEHandle):OsErr;
- VAR returnedType : DescType;
- actSize : longInt;
- myTextToken : TextToken;
- paramErr : OSErr;
-
- BEGIN
- paramErr := AEGetParamPtr(theAppleEvent,
- whatObject,
- typeMyText,
- returnedType,
- @myTextToken,
- SizeOf(myTextToken),
- actSize);
-
- IF (paramErr = noErr) THEN
- BEGIN
- { got a text token }
-
- theDocument := DPtrFromWindowPtr(myTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- TESetSelect(myTextToken.tokenOffset-1,
- myTextToken.tokenOffset+myTextToken.tokenLength-1,
- theHTE);
-
- END;
-
- SetSelectionOfAppleEventObject := paramErr;
-
- END; (* SetSelectionOfAppleEventObject *)
-
- { -----------------------------------------------------------------------
- Name: DoCutEdit
- Purpose: Performs a cut text operation on the current text selection
- -----------------------------------------------------------------------*}
-
- FUNCTION DoCutEdit(theAppleEvent, reply : AppleEvent; refCon : LONGINT): OSErr;
- VAR myErr : OSErr;
- theHTE : TEHandle;
- theDocument : DPtr;
-
- BEGIN
- myErr := SetSelectionOfAppleEventDirectObject(theAppleEvent,theDocument,theHTE);
-
- IF (myErr=noErr) THEN
- BEGIN
- DoTECutSectionRecalc(theDocument);
-
- myErr := ZeroScrap;
- TECut(theHTE);
- AdjustScrollbars(theDocument, FALSE);
- DrawPageExtras(theDocument);
- theDocument^.dirty := TRUE;
- END;
-
- DoCutEdit := myErr;
- END; (* DoCutEdit *)
-
- { -----------------------------------------------------------------------
- Name: DoCopyEdit
- Purpose: Performs a copy text operation on the text selection specified
- by the appleEvent direct object (if any)
- -----------------------------------------------------------------------*}
-
- FUNCTION DoCopyEdit(theAppleEvent, reply : AppleEvent; refCon : LONGINT): OSErr;
- VAR myErr : OSErr;
- theHTE : TEHandle;
- theDocument : DPtr;
- BEGIN
- (*
- Here we extract the information about what to copy from the
- directObject - if any
- *)
-
- myErr := SetSelectionOfAppleEventDirectObject(theAppleEvent,theDocument,theHTE);
-
- IF myErr=noErr THEN
- BEGIN
- myErr := ZeroScrap;
- TECopy(theHTE);
- END;
-
- IF (myErr=noErr) THEN
- IF (SetSelectionOfAppleEventObject(keyAEContainer,
- theAppleEvent,
- theDocument,
- theHTE) = noErr) THEN
- BEGIN
- DoTEPasteSectionRecalc(theDocument);
-
- TEStylPaste(theHTE);
-
- AdjustScrollBars(theDocument, FALSE);
-
- DrawPageExtras(theDocument);
-
- theDocument^.dirty := TRUE;
- END;
-
- DoCopyEdit := myErr;
- END; (* DoCopyEdit *)
-
- { -----------------------------------------------------------------------
- Name: DoPasteEdit
- Purpose: Performs a paste text operation on the text selection specified
- by the appleEvent direct object (if any)
- -----------------------------------------------------------------------*}
-
- FUNCTION DoPasteEdit(theAppleEvent, reply : AppleEvent; refCon : LONGINT): OSErr;
- VAR myErr : OSErr;
- theHTE : TEHandle;
- theDocument : DPtr;
- BEGIN
- myErr := SetSelectionOfAppleEventDirectObject(theAppleEvent,theDocument,theHTE);
-
- IF myErr=noErr THEN
- BEGIN
- DoTEPasteSectionRecalc(theDocument);
-
- TEStylPaste(theHTE);
-
- AdjustScrollbars(theDocument, FALSE);
-
- DrawPageExtras(theDocument);
-
- theDocument^.dirty := TRUE;
- END;
-
- DoPasteEdit := myErr;
- END; (* DoPasteEdit *)
-
- { -----------------------------------------------------------------------
- Name: DoDeleteEdit
- Purpose: Performs a delete text operation on the selection specified
- by the appleEvent direct object (if any)
- -----------------------------------------------------------------------*}
-
- FUNCTION DoDeleteEdit(theAppleEvent,reply : AppleEvent; refcon : longInt):OSErr;
- VAR myErr : OSErr;
- theHTE : TEHandle;
- theDocument : DPtr;
-
- BEGIN
- myErr := SetSelectionOfAppleEventDirectObject(theAppleEvent,theDocument,theHTE);
-
- IF myErr=noErr THEN
- BEGIN
- DoTEDeleteSectionRecalc(theDocument);
-
- TEDelete(theHTE);
-
- theDocument^.dirty := TRUE;
- AdjustScrollbars(theDocument, FALSE);
- DrawPageExtras(theDocument);
- END;
-
- DoDeleteEdit := myErr;
- END; (*DoDeleteEdit*)
-
- { -----------------------------------------------------------------------
- Name: SetTheFontOfTheTokenText
- Purpose: Sets the font of the text specified by theTextToken to
- the font in name.
- -----------------------------------------------------------------------*}
-
- PROCEDURE SetTheFontOfTheTokenText(theTextToken : textToken; name:Str255);
- VAR theDocument : DPtr;
- theNumber : INTEGER;
- theItem : INTEGER;
- oldPort : GrafPtr;
- newStyle : textStyle;
-
- BEGIN
- GetPort(oldPort);
-
- theDocument := DPtrFromWindowPtr(theTextToken.tokenWindow);
-
- GetFNum(name, theNumber);
-
- theItem := ItemForNamedFont(name); (* returns 0 if failed - i.e. SystemFont *)
-
- IF gFontMItem <> 0 THEN
- CheckItem(myMenus[fontM], gFontMItem, FALSE);
-
- gFontMItem := theItem;
- CheckItem(myMenus[fontM], gFontMItem, TRUE);
-
- theDocument^.theFont := theNumber;
-
- TESetSelect(theTextToken.tokenOffset-1,
- theTextToken.tokenOffset+theTextToken.tokenLength-1,
- theDocument^.theText);
-
- newStyle.tsFont := theNumber;
- TESetStyle(doFont, newStyle, TRUE, theDocument^.theText);
-
- AdjustScrollbars(theDocument, FALSE);
- DrawPageExtras(theDocument);
- theDocument^.dirty := TRUE;
-
- SetPort(oldPort);
- END; (* SetTheFontOfTheTokenText *)
-
- { -----------------------------------------------------------------------
- Name: SetTheSizeOfTheTokenText
- Purpose: Sets the size of the text specified by theTextToken to
- the size in theSize.
- -----------------------------------------------------------------------*}
-
- PROCEDURE SetTheSizeOfTheTokenText(theTextToken : textToken; theSize:INTEGER);
- VAR theDocument : DPtr;
- oldPort : GrafPtr;
- newStyle : textStyle;
-
- BEGIN
- GetPort(oldPort);
-
- theDocument := DPtrFromWindowPtr(theTextToken.tokenWindow);
-
- theDocument^.theSize := theSize;
-
- TESetSelect(theTextToken.tokenOffset-1,
- theTextToken.tokenOffset+theTextToken.tokenLength-1,
- theDocument^.theText);
-
- newStyle.tsSize := theSize;
- TESetStyle(doSize, newStyle, TRUE, theDocument^.theText);
-
- AdjustScrollbars(theDocument, FALSE);
- DrawPageExtras(theDocument);
- theDocument^.dirty := TRUE;
-
- SetPort(oldPort);
- END; (* SetTheSizeOfTheTokenText *)
-
- { -----------------------------------------------------------------------
- Name: SetTheStyleOfTheTokenText
- Purpose: Sets the style of the text specified by theTextToken to
- the style in theStyle.
- -----------------------------------------------------------------------*}
-
- PROCEDURE SetTheStyleOfTheTokenText(theTextToken : textToken;
- onStyle : Style;
- offStyle : Style);
- VAR theDocument : DPtr;
- oldPort : GrafPtr;
- newStyle : TextStyle;
- mode : INTEGER;
- wasContinuous : Boolean;
-
- BEGIN
- GetPort(oldPort);
-
- theDocument := DPtrFromWindowPtr(theTextToken.tokenWindow);
-
- theDocument^.theStyle := onStyle;
- TESetSelect(theTextToken.tokenOffset-1,
- theTextToken.tokenOffset+theTextToken.tokenLength-1,
- theDocument^.theText);
-
- { Check to see if off styles are on for whole selection }
- mode := doFace;
-
- wasContinuous := TEContinuousStyle(mode, newStyle, theDocument^.theText);
-
- if ((newStyle.tsFace * offStyle) <> offStyle) THEN (*not off styles are on for all *)
- BEGIN
- { switch on across board so that toggle off will clear all }
- newStyle.tsFace := offStyle - (newStyle.tsFace * offStyle);
- TESetStyle(doFace+doToggle, newStyle, false, theDocument^.theText);
- END;
-
- newStyle.tsFace := offStyle;
- TESetStyle(doFace+doToggle, newStyle, (onStyle=[]), theDocument^.theText); (* Toggle all to off *)
-
- mode := doFace;
-
- IF (onStyle<>[]) THEN
- BEGIN
- wasContinuous := TEContinuousStyle(mode, newStyle, theDocument^.theText);
- IF ((newStyle.tsFace * onStyle) <> onStyle) THEN (* are they on for only a few chars *)
- BEGIN
- (* Need to make all chars have these characteristics *)
-
- newStyle.tsFace := onStyle - (newStyle.tsFace * onStyle); (* take out those continuous *)
- TESetStyle(doFace+doToggle, newStyle, true, theDocument^.theText);
- END
- ELSE
- TESetStyle(0, newStyle, true, theDocument^.theText); (* Just Draw it, no changes *)
- END;
-
- AdjustScrollbars(theDocument, FALSE);
- DrawPageExtras(theDocument);
- theDocument^.dirty := TRUE;
-
- SetPort(oldPort);
- END; (* SetTheStyleOfTheTokenText *)
-
- { -----------------------------------------------------------------------
- Name: SetWindowProperty
- Purpose: Sets the window property specified in theWPTokenDesc to
- be that supplied in dataDesc.
- -----------------------------------------------------------------------*}
-
- FUNCTION SetWindowProperty(theWPTokenDesc:AEDesc; dataDesc:AEDesc):OSErr;
- VAR theNewName : Str255;
- theDocument : DPtr;
- err : OSErr;
- ignoreErr : OSErr;
- thePosnRect : Rect;
- theBoolean : Boolean;
- theHTE : TEHandle;
- oldPort : GrafPtr;
- thePosn : Point;
- theTHPrint : THPrint;
- theWindowPropToken : windowPropToken;
- newDesc : AEDesc;
- tokenSize : Size;
- tokenDesc : AEDesc;
- myTextToken : TextToken;
- hOffset : INTEGER;
- vOffset : INTEGER;
-
- BEGIN
- err := AECoerceDesc(theWPTokenDesc,typeMyWindowProp, newDesc);
-
- IF (err<>noErr) THEN
- BEGIN
- SetWindowProperty := err;
- Exit(SetWindowProperty);
- END;
-
- GetRawDataFromDescriptor(newDesc,
- @theWindowPropToken,
- SizeOf(theWindowPropToken),
- tokenSize);
-
- err := AEDisposeDesc(newDesc);
-
- GetPort(oldPort);
- SetPort(theWindowPropToken.tokenWindowToken);
-
- theDocument := DPtrFromWindowPtr(theWindowPropToken.tokenWindowToken);
-
- IF (theWindowPropToken.tokenProperty = pName) THEN
- BEGIN
- err := GetPStringFromDescriptor(dataDesc, theNewName);
- IF (err=noErr) THEN
- IF (theNewName = '') THEN
- err := errAEWrongDataType
- ELSE
- BEGIN
- SetWTitle(theWindowPropToken.tokenWindowToken, theNewName);
- theDocument^.theFileName := theNewName;
- theDocument^.dirty := TRUE;
- END;
- END;
-
- IF (theWindowPropToken.tokenProperty = pText) THEN
- BEGIN
- theHTE:=theDocument^.theText;
- TESetSelect(0, 32000, theHTE);
-
- DoTEDeleteSectionRecalc(theDocument);
- TEDelete(theHTE);
-
- err := GetStyledTextFromDescIntoTEHandle(dataDesc, theHTE);
-
- theDocument^.dirty := true;
- END;
-
- IF (theWindowPropToken.tokenProperty = pBounds) THEN
- BEGIN
- err := GetRectFromDescriptor(dataDesc, thePosnRect);
- WITH thePosnRect DO
- BEGIN
- { the rectangle is for the structure region, and is in global coordinates }
- { MoveWindow and SizeWindow apply to the content region, so we have to massage a little }
- { the massage is specific to the type of window we are using }
-
- thePosnRect.top := thePosnRect.top +
- WindowPeek(theWindowPropToken.tokenWindowToken)^.contRgn^^.rgnBBox.top -
- WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox.top;
-
- thePosnRect.left := thePosnRect.left +
- WindowPeek(theWindowPropToken.tokenWindowToken)^.contRgn^^.rgnBBox.left -
- WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox.left;
-
- thePosnRect.bottom := thePosnRect.bottom +
- WindowPeek(theWindowPropToken.tokenWindowToken)^.contRgn^^.rgnBBox.bottom -
- WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox.bottom;
-
- thePosnRect.right := thePosnRect.right +
- WindowPeek(theWindowPropToken.tokenWindowToken)^.contRgn^^.rgnBBox.right -
- WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox.right;
-
-
- IF EmptyRect(thePosnRect) THEN
- err := errAECorruptData
- ELSE
- BEGIN
- MoveWindow(theWindowPropToken.tokenWindowToken,
- thePosnRect.left,
- thePosnRect.top,
- FALSE);
- SizeWindow(theWindowPropToken.tokenWindowToken,
- thePosnRect.right- thePosnRect.left,
- thePosnRect.bottom-thePosnRect.top,
- TRUE);
- ResizeWindow(theDocument);
- END;
- END;
- END;
-
- IF (theWindowPropToken.tokenProperty = pPosition) THEN
- BEGIN
- err := GetPointFromDescriptor(dataDesc, thePosn);
- { the point is for the structure region, and is in global coordinates }
- { MoveWindow applies to the content region, so we have to massage a little }
-
- hOffset := WindowPeek(theWindowPropToken.tokenWindowToken)^.contRgn^^.rgnBBox.left -
- WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox.left;
-
- vOffset := WindowPeek(theWindowPropToken.tokenWindowToken)^.contRgn^^.rgnBBox.top -
- WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox.top;
-
- thePosn.v := thePosn.v + vOffset;
- thePosn.h := thePosn.h + hOffset;
-
- MoveWindow(theWindowPropToken.tokenWindowToken,
- thePosn.h,
- thePosn.v,
- FALSE);
-
- ResizeWindow(theDocument);
- END;
-
- IF (theWindowPropToken.tokenProperty = pIsZoomed) THEN
- BEGIN
- err := GetBooleanFromDescriptor(dataDesc, theBoolean);
- IF theBoolean THEN
- ZoomWindow(thePort,
- inZoomOut,
- FALSE)
- ELSE
- ZoomWindow(thePort,
- inZoomIn,
- FALSE);
-
- ResizeWindow(theDocument);
- END;
-
- IF (theWindowPropToken.tokenProperty = pVisible) THEN
- BEGIN
- err := GetBooleanFromDescriptor(dataDesc, theBoolean);
- IF theBoolean THEN
- ShowWindow(theWindowPropToken.tokenWindowToken)
- ELSE
- HideWindow(theWindowPropToken.tokenWindowToken);
- END;
-
- IF (theWindowPropToken.tokenProperty = pPageSetup) THEN
- BEGIN
- err := GetTHPrintFromDescriptor(dataDesc,theTHPrint);
-
- IF (theTHPrint<>NIL) THEN
- BEGIN
- IF (theDocument^.thePrintSetup <> NIL) THEN
- DisposHandle(Handle(theDocument^.thePrintSetup));
-
- theDocument^.thePrintSetup := theTHPrint;
-
- ResizePageSetupForDocument(theDocument);
- END;
-
- END;
-
- IF (theWindowPropToken.tokenProperty = pShowBorders) THEN
- BEGIN
- err := GetBooleanFromDescriptor(dataDesc, theBoolean);
- theDocument^.showBorders := theBoolean;
- IF theBoolean THEN
- DrawPageExtras(theDocument) (* Does the clipping as well as drawing borders/page breaks *)
- ELSE
- InvalidateDocument(theDocument);
- END;
-
- IF (theWindowPropToken.tokenProperty = pSelection) THEN
- BEGIN
- err := AECoerceDesc(dataDesc, typeMyText, tokenDesc);
-
- GetRawDataFromDescriptor(tokenDesc,
- Ptr(@myTextToken),
- sizeof(myTextToken),
- tokenSize);
-
- ignoreErr := AEDisposeDesc(tokenDesc);
-
- IF (err = noErr) THEN
- BEGIN
- (* got a text token *)
-
- theDocument := DPtrFromWindowPtr(myTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- TESetSelect(myTextToken.tokenOffset-1,
- myTextToken.tokenOffset+myTextToken.tokenLength-1,
- theHTE);
- END;
- END;
-
- IF (theWindowPropToken.tokenProperty = pIndex) OR
- (theWindowPropToken.tokenProperty = pIsModal) OR
- (theWindowPropToken.tokenProperty = pIsResizable) OR
- (theWindowPropToken.tokenProperty = pHasTitleBar) OR
- (theWindowPropToken.tokenProperty = pHasCloseBox) OR
- (theWindowPropToken.tokenProperty = pIsFloating) OR
- (theWindowPropToken.tokenProperty = pIsZoomable) OR
- (theWindowPropToken.tokenProperty = pIsModified) THEN
- BEGIN
- err := errAEEventNotHandled; (* We don't allow these to be set *)
- END;
-
- SetPort(oldPort);
-
- SetWindowProperty := err;
-
- END; (* SetWindowProperty *)
-
- { -----------------------------------------------------------------------
- Name: AddDescStyleItem
- Purpose: Adds the kAEXXXX style to theStyle.
- -----------------------------------------------------------------------*}
-
- PROCEDURE AddDescStyleItem(theDesc: DescType; VAR theStyle:Style);
- VAR ctr : StyleItem;
-
- BEGIN
- IF theDesc = kAEBold THEN
- theStyle := theStyle+[bold]
- ELSE
- IF theDesc = kAEItalic THEN
- theStyle := theStyle+[italic]
- ELSE
- IF theDesc = kAEUnderline THEN
- theStyle := theStyle+[underline]
- ELSE
- IF theDesc = kAEOutline THEN
- theStyle := theStyle+[outline]
- ELSE
- IF theDesc = kAEShadow THEN
- theStyle := theStyle+[shadow]
- ELSE
- IF theDesc = kAECondensed THEN
- theStyle := theStyle+[condense]
- ELSE
- IF theDesc = kAEExpanded THEN
- theStyle := theStyle+[extend]
- ELSE
- IF theDesc = kAEPlain THEN
- theStyle := [];
- END; (* AddDescStyleItem *)
-
- FUNCTION MakeStyleFromAEList(styleList : AEDescList; VAR theStyle : Style; VAR hadPlain:BOOLEAN):OSErr;
- VAR myErr : OSErr;
- styleDesc : DescType;
- itemsInList : LongInt;
- actSize : LongInt;
- keywd : AEKeyWord;
- typeCode : DescType;
-
- BEGIN
- hadPlain := FALSE;
- theStyle := [];
-
- myErr := AECountItems(styleList, itemsInList);
- WHILE (itemsInList>0) DO
- IF (myErr=noErr) THEN
- BEGIN
- myErr := AEGetNthPtr(styleList,
- itemsInList,
- typeEnumerated,
- keywd,
- typeCode,
- @styleDesc,
- sizeof(styleDesc),
- actSize);
-
- AddDescStyleItem(styleDesc, theStyle);
-
- IF (styleDesc = kAEPlain) THEN
- BEGIN
- itemsInList := 0;
- hadPlain := TRUE;
- END
- ELSE
- itemsInList := itemsInList - 1;
- END;
-
- MakeStyleFromAEList := myErr;
- END; (*MakeStyleFromAEList*)
-
- FUNCTION GetTextStyles(dataDesc:AEDesc; VAR onStyles:Style; VAR offStyles:Style):OSErr;
- VAR myErr : OSErr;
- ignoreErr : OSErr;
- textSDesc : AEDescList;
- onDesc : AEDescList;
- offDesc : AEDescList;
- hadPlain : BOOLEAN;
-
- BEGIN
- textSDesc.dataHandle := NIL;
- onDesc.dataHandle := NIL;
- offDesc.dataHandle := NIL;
-
- onStyles := [];
- offStyles := [];
-
- myErr := AECoerceDesc(dataDesc, typeAERecord, textSDesc);
-
- IF (myErr=noErr) THEN
- myErr := AEGetKeyDesc(textSDesc, keyAEOnStyles, typeAEList, onDesc);
-
- IF (myErr=noErr) THEN
- myErr := AEGetKeyDesc(textSDesc, keyAEOffStyles, typeAEList, offDesc);
-
- IF (myErr=noErr) THEN
- myErr := MakeStyleFromAEList(onDesc, onStyles, hadPlain);
-
- IF (hadPlain) THEN
- offStyles := [bold,italic,underline,outline,shadow,condense,extend]
- ELSE
- BEGIN
- IF (myErr=noErr) THEN
- myErr := MakeStyleFromAEList(offDesc, offStyles, hadPlain);
-
- IF (hadPlain) THEN
- myErr := errAEEventFailed;
- END;
-
- IF (textSDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(textSDesc);
-
- IF (onDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(onDesc);
-
- IF (offDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(offDesc);
-
- GetTextStyles := myErr;
- END; (* GetTextStyles *)
-
- { -----------------------------------------------------------------------
- Name: SetTextProperty
- Purpose: Sets the text property specfied by theTextPropToken to
- that in dataDesc.
- -----------------------------------------------------------------------*}
-
- FUNCTION SetTextProperty(tokenDesc: AEDesc; dataDesc:AEDesc):OSErr;
- VAR theHTE : TEHandle;
- theDoc : DPtr;
- name : Str255;
- theSize : INTEGER;
- myErr : OSErr;
- onStyle : Style;
- offStyle : Style;
- theTextPropToken : textPropToken;
- newDesc : AEDesc;
- tokenSize : Size;
-
- BEGIN
- newDesc.dataHandle := NIL;
-
- myErr := AECoerceDesc(tokenDesc,typeMyTextProp, newDesc);
- IF (myErr = noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theTextPropToken,
- SizeOf(theTextPropToken),
- tokenSize);
- myErr := AEDisposeDesc(newDesc);
- END
- ELSE
- BEGIN
- SetTextProperty := myErr;
- Exit(SetTextProperty);
- END;
-
- theDoc := DPtrFromWindowPtr(theTextPropToken.propertyTextToken.tokenWindow);
- theDoc^.dirty := TRUE;
-
- IF (theTextPropToken.propertyProperty = pText) THEN
- BEGIN
- theHTE := theDoc^.theText;
- TESetSelect(theTextPropToken.propertyTextToken.tokenOffset-1,
- theTextPropToken.propertyTextToken.tokenOffset+
- theTextPropToken.propertyTextToken.tokenLength-1,
- theHTE);
-
- DoTEDeleteSectionRecalc(theDoc);
- TEDelete(theHTE);
-
- myErr := GetStyledTextFromDescIntoTEHandle(dataDesc, theHTE);
-
- SetTextProperty := myErr;
- Exit(SetTextProperty);
- END;
-
- IF (theTextPropToken.propertyProperty = pFont) THEN
- BEGIN
- myErr := GetPStringFromDescriptor(dataDesc, name);
-
- SetTheFontOfTheTokenText(theTextPropToken.propertyTextToken,
- name);
-
- SetTextProperty:=noErr;
- Exit(SetTextProperty);
- END;
-
- IF (theTextPropToken.propertyProperty = pPointSize) THEN
- BEGIN
- myErr := GetIntegerFromDescriptor(dataDesc, theSize);
- SetTheSizeOfTheTokenText(theTextPropToken.propertyTextToken,
- theSize);
-
- SetTextProperty := noErr;
- Exit(SetTextProperty);
- END;
-
- IF (theTextPropToken.propertyProperty = pTextStyles) THEN
- BEGIN
- onStyle := [];
- offStyle := [];
-
- myErr := GetTextStyles(dataDesc, onStyle, offStyle);
-
- IF (onStyle*offStyle<>[]) THEN
- myErr := errAEEventFailed
- ELSE
- SetTheStyleOfTheTokenText(theTextPropToken.propertyTextToken,
- onStyle,
- offStyle);
-
- SetTextProperty := myErr;
- Exit(SetTextProperty);
- END;
-
- SetTextProperty := errAEWrongDataType;
-
- END; (* SetTextProperty *)
-
- { -----------------------------------------------------------------------
- Name: HandleSetData
- Purpose: Resolves the object into a token (could be one of many) and
- the sets the data of that object to dataDesc.
- -----------------------------------------------------------------------*}
-
- FUNCTION HandleSetData(theObj: AEDesc; dataDesc: AEDesc): OSErr;
- VAR myErr : OSErr;
- newDesc : AEDesc;
- theDocument : DPtr;
- theHTE : TEHandle;
- theTextToken : textToken;
- tokenSize : Size;
- objTokenDesc : AEDesc;
- ignoreErr : OSErr;
-
- BEGIN
- objTokenDesc.dataHandle := NIL;
- newDesc.dataHandle := NIL;
-
- (*
- Coerce theObj into a token which we can use -
- then set the property or data for that token
- *)
-
- myErr:= AEResolve(theObj ,kAEIDoMinimum, objTokenDesc);
-
- (* We don't actually allow ANY app property setting, but
- just incase we'll decode looking for an typeMyApplProp and flag an error
- *)
-
- IF (objTokenDesc.descriptorType = typeMyApplProp) OR
- (objTokenDesc.descriptorType = typeMyMenu ) OR
- (objTokenDesc.descriptorType = typeMyMenuProp) OR
- (objTokenDesc.descriptorType = typeMyMenuItem) OR
- (objTokenDesc.descriptorType = typeMyItemProp) THEN
- myErr := errAEWrongDataType
- ELSE
- IF (objTokenDesc.descriptorType = typeMyWindowProp) THEN
- myErr := SetWindowProperty(objTokenDesc, dataDesc)
- ELSE
- IF (objTokenDesc.descriptorType = typeMyTextProp) THEN
- myErr := SetTextProperty(objTokenDesc, dataDesc)
- ELSE
- IF (objTokenDesc.descriptorType = typeMyText) THEN
- IF AECoerceDesc(objTokenDesc,typeMyText,newDesc) = noErr THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theTextToken,
- SizeOf(theTextToken),
- tokenSize);
-
- theDocument := DPtrFromWindowPtr(theTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- TESetSelect(theTextToken.tokenOffset-1,
- theTextToken.tokenOffset+
- theTextToken.tokenLength-1,
- theHTE);
-
- DoTEDeleteSectionRecalc(theDocument);
- TEDelete(theHTE);
-
- myErr := GetStyledTextFromDescIntoTEHandle(dataDesc, theHTE);
-
- theDocument^.dirty := TRUE;
- END;
-
- IF (objTokenDesc.dataHandle<>NIL) THEN
- ignoreErr:=AEDisposeDesc(objTokenDesc);
-
- HandleSetData := myErr;
-
- END; { HandleSetData }
-
- (*
- A few convenient FORWARDS...
- *)
-
- FUNCTION MakeWindowObj( theWindow : WindowPtr;
- VAR dMyDoc : AEDesc):OSErr; FORWARD;
-
- FUNCTION MakeSelTextObj(theWindow : WindowPtr;
- theTextEditHandle : TEHandle;
- VAR selTextObj : AEDesc): OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- dNull : AEDesc;
- dMyDoc : AEDesc;
- startOfs : AEDesc;
- endOfs : AEDesc;
- startObj : AEDesc;
- endObj : AEDesc;
- rangeDesc : AEDesc;
- startChar : LongInt;
- endChar : LongInt;
- spotFlag : BOOLEAN;
-
- BEGIN
- myErr := noErr;
-
- IF (theWindow=nil) THEN
- BEGIN
- MakeSelTextObj:=noErr;
- Exit(MakeSelTextObj);
- END;
-
- selTextObj.dataHandle := nil;
- dMyDoc.dataHandle := nil;
- startObj.dataHandle := nil;
- endObj.dataHandle := nil;
-
- (*
- make the window object
- *)
-
- myErr := MakeWindowObj(theWindow, dMyDoc);
-
- IF (myErr=noErr) THEN
- BEGIN
- { get the start and end of selection }
-
- WITH theTextEditHandle^^ DO
- BEGIN
- startChar := selStart+1; { start counting obj's from 1, not 0 }
- endChar := selEnd;
- spotFlag := (selStart = selEnd);
- END;
-
- myErr := CreateOffsetDescriptor(startChar, startOfs);
-
- IF myErr=noErr THEN
- IF spotFlag THEN
- myErr := CreateObjSpecifier( cSpot,
- dMyDoc,
- formAbsolutePosition,
- startOfs,
- TRUE,
- selTextObj)
- ELSE
- BEGIN
- { not a spot - must represent as range }
- { make obj for start char }
-
- myErr := AECreateDesc(typeNull, nil , 0, dNull);
-
- myErr := CreateObjSpecifier(cChar, dNull, formAbsolutePosition, startOfs, FALSE, startObj);
-
- IF (myErr=noErr) THEN
- myErr := CreateOffsetDescriptor(endChar, endOfs);
-
- IF (myErr=noErr) THEN
- myErr := CreateObjSpecifier(cChar, dNull, formAbsolutePosition, endOfs, FALSE, endObj);
-
- IF (myErr=noErr) THEN
- myErr := CreateRangeDescriptor(startObj,
- endObj,
- FALSE,
- rangeDesc);
-
- if (myErr=noErr) then
- BEGIN
- myErr := CreateObjSpecifier(cChar,
- dMyDoc,
- formRange,
- rangeDesc,
- TRUE,
- selTextObj);
-
- END;
-
- IF (startObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(startObj);
-
- IF (endObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(endObj);
-
- IF (startOfs.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(startOfs);
-
- IF (endOfs.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(endOfs);
- END;
- END;
-
- MakeSelTextObj := myErr;
- END; { MakeSelTextObj }
-
- { -----------------------------------------------------------------------
- Name: DoSetData
- Purpose: Handles the SetData Apple Event, extracting the direct
- object (which says what to set) and the data (what to set
- it to).
- -----------------------------------------------------------------------*}
-
- FUNCTION DoSetData(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- myDirObj : AEDesc;
- myDataDesc : AEDesc;
-
- BEGIN
- myDataDesc.dataHandle := NIL;
- myDirObj.dataHandle := NIL;
-
- { pick up the direct object, which is the object whose data is to be set }
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- { now the data to set it to - typeWildCard means get as is}
- IF (myErr = noErr) THEN
- myErr := AEGetParamDesc(theAppleEvent,
- keyAEData,
- typeWildCard,
- myDataDesc);
-
- { missing any parameters? }
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { set the data }
- IF (myErr = noErr) THEN
- myErr := HandleSetData(myDirObj,myDataDesc);
-
- IF (myDataDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(myDataDesc);
-
- IF (myDirObj.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(myDirObj);
-
- DoSetData := myErr;
- END; { DoSetData }
-
- PROCEDURE StyleTokConst(theStyleItem:StyleItem; VAR thekConst:DescType);
- BEGIN
- CASE theStyleItem OF
- bold : thekConst := kAEBold;
- italic : thekConst := kAEItalic;
- underline : thekConst := kAEUnderline;
- outline : thekConst := kAEOutline;
- shadow : thekConst := kAEShadow;
- condense : thekConst := kAECondensed;
- extend : thekConst := kAEExpanded;
- END;
- END; (*StyleTokConst*)
-
- { -----------------------------------------------------------------------
- Name: BuildTypeTextStylesDesc
- Purpose: Given on and off styles, BuildTextStylesDesc creates an typeTextStyles
- descriptor record containing a pair of lists, keyAEOnStyles
- and keyAEOffStyles. keyAEOffStyles contains all the styles
- we support that are not in theStyle.
- -----------------------------------------------------------------------*}
-
- FUNCTION BuildTypeTextStylesDesc(onStyles,offStyles :Style; VAR resultDesc: AEDesc):OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- myStyleItem : styleItem;
- styleConst : DescType;
- onStylesDesc : AEDesc;
- offStylesDesc : AEDesc;
- dataDesc : AEDesc;
-
- BEGIN
- onStylesDesc.dataHandle := NIL;
- offStylesDesc.dataHandle := NIL;
- dataDesc.dataHandle := NIL;
-
- myErr := AECreateList(NIL, 0, TRUE, dataDesc);
-
- myErr := AECreateList(NIL, 0, FALSE, onStylesDesc);
- myErr := AECreateList(NIL, 0, FALSE, offStylesDesc);
-
- FOR myStyleItem := bold TO extend DO
- IF (myErr=noErr) THEN
- BEGIN
- StyleTokConst(myStyleItem, styleConst);
- IF (myStyleItem IN onStyles) THEN
- myErr := AEPutPtr(onStylesDesc,
- 0, {add to end of list}
- typeEnumerated, { text for style name }
- @styleConst,
- sizeof(styleConst));
-
- IF (myStyleItem IN offStyles) THEN
- myErr := AEPutPtr(offStylesDesc,
- 0, {add to end of list}
- typeEnumerated, { text for style name }
- @styleConst,
- sizeof(styleConst))
- END;
-
- IF (myErr=noErr) THEN
- myErr := AEPutKeyDesc(dataDesc, keyAEOnStyles, onStylesDesc);
-
- IF (myErr=noErr) THEN
- myErr := AEPutKeyDesc(dataDesc, keyAEOffStyles, offStylesDesc);
-
- IF (myErr=noErr) THEN
- myErr := AECoerceDesc(dataDesc, typeTextStyles, resultDesc);
-
- IF (onStylesDesc.dataHandle <> NIL) THEN
- ignoreErr := AEDisposeDesc(onStylesDesc);
-
- IF (offStylesDesc.dataHandle <> NIL) THEN
- ignoreErr := AEDisposeDesc(offStylesDesc);
-
- IF (dataDesc.dataHandle <> NIL) THEN
- ignoreErr := AEDisposeDesc(dataDesc);
-
- BuildTypeTextStylesDesc := myErr;
- END; (* BuildTextStylesDesc *)
-
- FUNCTION BuildTextStylesDesc(theStyle : Style; VAR resultDesc:AEDesc) : OSErr;
- VAR
- myStyleItem : StyleItem;
- onStyles : Style;
- offStyles : Style;
-
- BEGIN
- onStyles := [];
- offStyles := [];
-
- FOR myStyleItem := bold TO extend DO
- BEGIN
- IF (myStyleItem IN theStyle) THEN
- onStyles := onStyles + [myStyleItem]
- ELSE
- offStyles := offStyles + [myStyleItem];
- END;
-
- BuildTextStylesDesc := BuildTypeTextStylesDesc(onStyles, offStyles, resultDesc);
-
- END; (* BuildTextStylesDesc *)
-
- FUNCTION BuildStyledTextDesc(theHTE : TEHandle; start:INTEGER; howLong:INTEGER; VAR resultDesc:AEDesc):OSErr;
- VAR
- listDesc : AEDesc;
- oldSelStart : INTEGER;
- oldSelEnd : INTEGER;
- myStScrpHandle : StScrpHandle;
- myErr : OSErr;
- ignoreErr : OSErr;
-
- BEGIN
- listDesc.dataHandle := nil;
-
- oldSelStart := theHTE^^.selStart;
- oldSelEnd := theHTE^^.selEnd;
-
- TESetSelect(start-1, start+howLong-2, theHTE);
-
- myErr := AECreateList(nil, 0, TRUE, listDesc);
-
- HLock(Handle(theHTE^^.hText));
-
- IF (myErr=noErr) THEN
- myErr := AEPutKeyPtr(listDesc,
- keyAEText,
- typeChar,
- Ptr(ORD4(@theHTE^^.hText^^)+start-1),
- howLong);
-
- HUnlock(Handle(theHTE^^.hText));
-
- myStScrpHandle := GetStylScrap(theHTE);
-
- IF (myStScrpHandle<>NIL) THEN
- BEGIN
- HLock(Handle(myStScrpHandle));
-
- IF (myErr=noErr) THEN
- myErr := AEPutKeyPtr(listDesc,
- keyAEStyles,
- typeScrapStyles,
- Ptr(myStScrpHandle^),
- GetHandleSize(Handle(myStScrpHandle)));
-
- HUnlock(Handle(myStScrpHandle));
- END
- ELSE
- myErr := AEPutKeyPtr(listDesc,
- keyAEStyles,
- typeScrapStyles,
- NIL,
- 0);
-
- IF (myErr=noErr) THEN
- myErr := AECoerceDesc(listDesc, typeStyledText, resultDesc); (* should be typeIntlText *)
-
- IF (listDesc.dataHandle <> NIL) THEN
- ignoreErr := AEDisposeDesc(listDesc);
-
- TESetSelect(oldSelStart, oldSelEnd, theHTE);
-
- BuildStyledTextDesc := myErr;
- END;
-
- { -----------------------------------------------------------------------
- Name: GetTextProperty
- Purpose: Fills dataDesc with the requested text property.
- -----------------------------------------------------------------------*}
-
- FUNCTION GetTextProperty(theTokenDesc:AEDesc; VAR dataDesc: AEDesc):OSErr;
- VAR theDocument : DPtr;
- theHTE : TEHandle;
- fontName : Str255;
- theSize : INTEGER;
- oldPort : GrafPtr;
- theTextStyle : TextStyle;
- lineHeight : INTEGER;
- fontAscent : INTEGER;
- theTextPropToken: textPropToken;
- newDesc : AEDesc;
- myErr : OSErr;
- tokenSize : Longint;
-
- BEGIN
- myErr := AECoerceDesc(theTokenDesc, typeMyTextProp, newDesc);
- IF (myErr = noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theTextPropToken,
- SizeOf(theTextPropToken),
- tokenSize);
- myErr:= AEDisposeDesc(newDesc);
- END
- ELSE
- BEGIN
- GetTextProperty := myErr;
- Exit(GetTextProperty);
- END;
-
- (*
- For each property we build a descriptor to be returned as the reply.
- *)
-
- theDocument := DPtrFromWindowPtr(theTextPropToken.propertyTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- TEGetStyle (theTextPropToken.propertyTextToken.tokenOffset-1,
- theTextStyle,
- lineHeight,
- fontAscent,
- theHTE);
-
- IF (theTextPropToken.propertyProperty = pText) THEN
- BEGIN
- myErr := BuildStyledTextDesc( theHTE,
- theTextPropToken.propertyTextToken.tokenOffset,
- theTextPropToken.propertyTextToken.tokenLength,
- dataDesc);
- END
- ELSE
-
- IF (theTextPropToken.propertyProperty = pFont) THEN
- BEGIN
-
- GetFontName(theTextStyle.tsFont, fontName);
-
- myErr := AECreateDesc(typeChar,
- POINTER(ORD4(@fontName)+1),
- length(fontName),
- dataDesc);
- END
- ELSE
-
- IF (theTextPropToken.propertyProperty = pTextStyles) THEN
- BEGIN
- myErr := BuildTextStylesDesc(theTextStyle.tsFace, dataDesc);
- END
- ELSE
-
- IF (theTextPropToken.propertyProperty = pPointSize) THEN
- BEGIN
- myErr := CreateOffsetDescriptor(theTextStyle.tsSize, dataDesc);
- END
- ELSE
-
- IF (theTextPropToken.propertyProperty = pScriptTag) THEN
- BEGIN
- myErr := CreateOffsetDescriptor(smSystemScript, dataDesc);
- END
- ELSE
-
- IF (theTextPropToken.propertyProperty = pStringWidth) THEN
- BEGIN
- GetPort(oldPort);
- SetPort(theTextPropToken.propertyTextToken.tokenWindow);
-
- HLock(Handle(theHTE^^.hText));
- theSize := TextWidth(@theHTE^^.hText,
- theTextPropToken.propertyTextToken.tokenOffset-1,
- theTextPropToken.propertyTextToken.tokenLength);
-
- HUnLock(Handle(theHTE^^.hText));
-
- SetPort(oldPort);
- myErr := CreateOffsetDescriptor(theSize, dataDesc);
- END
- ELSE
-
- IF (theTextPropToken.propertyProperty = pColor) THEN
- BEGIN
- myErr := AECreateDesc(typeRGBColor,
- @theTextStyle.tsColor,
- sizeof(theTextStyle.tsColor),
- dataDesc);
- END
- ELSE
- myErr := errAEEventNotHandled;
-
- GetTextProperty := myErr;
- END; (*GetTextProperty*)
-
- { -----------------------------------------------------------------------
- Name: GetWindowProperty
- Purpose: Fills dataDesc with the requested window property.
- -----------------------------------------------------------------------*}
-
- FUNCTION GetWindowProperty(theWPTokenObj:AEDesc ;VAR dataDesc:AEDesc):OSErr;
- TYPE RectHandle = ^RectPtr;
- RectPtr = ^Rect;
-
- VAR theErr : OSErr;
- theName : Str255;
- theBoolean : Boolean;
- theRect : Rect;
- thePoint : Point;
- winRect : Rect;
- userRect : Rect;
- theIndex : INTEGER;
- theDocument : DPtr;
- theHTE : TEHandle;
- theWindowPropToken : windowPropToken;
- tokenSize : Longint;
- newDesc : AEDesc;
-
- BEGIN
- theErr := AECoerceDesc(theWPTokenObj,typeMyWindowProp,newDesc);
-
- IF (theErr = noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theWindowPropToken,
- SizeOf(theWindowPropToken),
- tokenSize);
-
- theErr := AEDisposeDesc(newDesc);
- END
- ELSE
- BEGIN
- GetWindowProperty := theErr;
- Exit(GetWindowProperty);
- END;
-
- IF (theWindowPropToken.tokenProperty = pName) THEN
- BEGIN
- GetWTitle(theWindowPropToken.tokenWindowToken,theName);
- theErr := AECreateDesc(typeChar,
- Ptr(ORD4(@theName)+1),
- Length(theName),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pText) THEN
- BEGIN
- theDocument := DPtrFromWindowPtr(theWindowPropToken.tokenWindowToken);
- theHTE := theDocument^.theText;
-
- theErr := BuildStyledTextDesc(theHTE,
- 1,
- theHTE^^.teLength,
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pBounds) THEN
- BEGIN
- SetPort(theWindowPropToken.tokenWindowToken);
-
- theRect := WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox;
-
- theErr := AECreateDesc(typeQDRectangle,
- @theRect,
- sizeOf(theRect),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pPosition) THEN
- BEGIN
- thePoint := WindowPeek(theWindowPropToken.tokenWindowToken)^.strucRgn^^.rgnBBox.topLeft;
-
- theErr := AECreateDesc(typeQDPoint,
- @thePoint,
- sizeOf(thePoint),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pVisible) THEN
- BEGIN
- theBoolean := WindowPeek(theWindowPropToken.tokenWindowToken)^.visible;
-
- theErr := AECreateDesc(typeBoolean,
- @theBoolean,
- sizeOf(theBoolean),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pIsModal) THEN
- BEGIN
- theBoolean := FALSE;
-
- theErr := AECreateDesc(typeBoolean,
- @theBoolean,
- sizeOf(theBoolean),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pShowBorders) THEN
- BEGIN
- theDocument := DPtrFromWindowPtr(theWindowPropToken.tokenWindowToken);
- theBoolean := theDocument^.showBorders;
-
- theErr := AECreateDesc(typeBoolean,
- @theBoolean,
- sizeOf(theBoolean),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pIsZoomed) THEN
- BEGIN
- IF (WindowPeek(theWindowPropToken.tokenWindowToken)^.spareFlag) THEN
- BEGIN
- SetPort(theWindowPropToken.tokenWindowToken);
-
- userRect := RectHandle(WindowPeek(thePort)^.dataHandle)^^;
- winRect := thePort^.portRect;
- LocalToGlobal(winRect.topLeft);
- LocalToGlobal(winRect.botRight);
-
- theBoolean := NOT EqualRect(userRect,winRect); (* right way?? - ***LATER *)
-
- END
- ELSE
- theBoolean := FALSE;
-
- theErr := AECreateDesc(typeBoolean,
- @theBoolean,
- sizeOf(theBoolean),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pIsResizable) OR
- (theWindowPropToken.tokenProperty = pHasTitleBar) OR
- (theWindowPropToken.tokenProperty = pHasCloseBox) OR
- (theWindowPropToken.tokenProperty = pIsZoomable) THEN
-
- BEGIN
- theBoolean := TRUE;
-
- theErr := AECreateDesc(typeBoolean,
- @theBoolean,
- sizeOf(theBoolean),
- dataDesc);
- END
- ELSE
- IF (theWindowPropToken.tokenProperty = pIsFloating) THEN
-
- BEGIN
- theBoolean := FALSE;
-
- theErr := AECreateDesc(typeBoolean,
- @theBoolean,
- sizeOf(theBoolean),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pIsModified) THEN
- BEGIN
- theDocument := DPtrFromWindowPtr(theWindowPropToken.tokenWindowToken);
-
- theBoolean := theDocument^.dirty;
-
- theErr := AECreateDesc(typeBoolean,
- @theBoolean,
- sizeOf(theBoolean),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pIndex) THEN
- BEGIN
- theIndex := 0;
- IF (theWindowPropToken.tokenWindowToken<>nil) THEN
- REPEAT
- theIndex := theIndex+1;
- UNTIL (theWindowPropToken.tokenWindowToken=GetWindowPtrOfNthWindow(theIndex));
-
- theErr := AECreateDesc(typeShortInteger,
- @theIndex,
- sizeOf(theIndex),
- dataDesc);
- END
- ELSE
-
- IF (theWindowPropToken.tokenProperty = pPageSetup) THEN
- BEGIN
- theDocument := DPtrFromWindowPtr(theWindowPropToken.tokenWindowToken);
-
- theErr := AECreateDesc(typeTPrint,
- Ptr(theDocument^.thePrintSetup^),
- SizeOf(TPrint),
- dataDesc);
- END
- ELSE
- IF (theWindowPropToken.tokenProperty = pSelection) THEN
- BEGIN
- theDocument := DPtrFromWindowPtr(theWindowPropToken.tokenWindowToken);
-
- theErr := MakeSelTextObj(theWindowPropToken.tokenWindowToken,
- theDocument^.theText,
- dataDesc);
- END
- ELSE
- theErr := kAEGenericErr;
-
- GetWindowProperty := theErr;
- END; (* GetWindowProperty *)
-
- {* -----------------------------------------------------------------------
- Name: GetApplicationProperty
- Purpose: Fills dataDesc with the requested application property.
- -----------------------------------------------------------------------*}
-
- FUNCTION GetApplicationProperty(theTokenObj:AEDesc; VAR dataDesc: AEDesc): OSErr;
- VAR theErr : OSErr;
- theName : Str255;
- isFront : Boolean;
- theApplPropToken : ApplPropToken;
- newDesc : AEDesc;
- tokenSize : LongInt;
-
- BEGIN
- theErr := AECoerceDesc(theTokenObj,typeMyApplProp,newDesc);
- IF (theErr=noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theApplPropToken,
- SizeOf(theApplPropToken),
- tokenSize);
-
- theErr := AEDisposeDesc(newDesc);
- END
- ELSE
- BEGIN
- GetApplicationProperty := theErr;
- Exit(GetApplicationProperty);
- END;
-
- IF (theApplPropToken.tokenApplProperty = pName) THEN
- BEGIN
- theName:= '7Edit';
- theErr := AECreateDesc(typeChar,
- Ptr(ORD4(@theName)+1),
- Length(theName),
- dataDesc);
- END
- ELSE
- IF (theApplPropToken.tokenApplProperty = pVersion) THEN
- BEGIN
- theName:= '3.0d5';
- theErr := AECreateDesc(typeChar,
- Ptr(ORD4(@theName)+1),
- Length(theName),
- dataDesc);
- END
- ELSE
- IF (theApplPropToken.tokenApplProperty = pIsFrontProcess) THEN
- BEGIN
- isFront := NOT gInBackground;
- theErr := AECreateDesc(typeBoolean,
- @isFront,
- sizeof(isFront),
- dataDesc);
- END
- ELSE
- theErr := kAEGenericErr;
-
- GetApplicationProperty := theErr;
- END; (* GetApplicationProperty *)
-
- (* -----------------------------------------------------------------------
- Name: GetMenuProperty
- Purpose: Fills dataDesc with the requested menu property.
- -----------------------------------------------------------------------**)
-
- FUNCTION GetMenuProperty(VAR theObjToken:AEDesc; VAR dataDesc: AEDesc):OSErr;
- VAR
- theErr : OSErr;
- theName : Str255;
- theMenuPropToken : MenuPropToken;
- newDesc : AEDesc;
- tokenSize : Size;
-
- BEGIN
- theErr := AECoerceDesc(theObjToken, typeMyMenuProp, newDesc);
- IF (theErr=noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- Ptr(@theMenuPropToken),
- sizeof(theMenuPropToken),
- tokenSize);
-
- theErr := AEDisposeDesc(newDesc);
- END
- ELSE
- BEGIN
- GetMenuProperty := theErr;
- Exit(GetMenuProperty);
- END;
-
- theErr := kAEGenericErr;
-
- IF (theMenuPropToken.theMenuProp = pName) THEN
- BEGIN
- theName := theMenuPropToken.theMenuToken.theTokenMenu^^.menuData;
- theErr := AECreateDesc(typeChar,
- Ptr(@theName[1]),
- length(theName),
- dataDesc);
- END;
-
- IF (theMenuPropToken.theMenuProp = pMenuID) THEN
- BEGIN
- theErr := AECreateDesc(typeShortInteger,
- Ptr(@theMenuPropToken.theMenuToken.theTokenID),
- sizeof(theMenuPropToken.theMenuToken.theTokenID),
- dataDesc);
- END;
-
- GetMenuProperty:=theErr;
- END; (* GetMenuProperty *)
-
- (** -----------------------------------------------------------------------
- Name: GetMenuItemProperty
- Purpose: Fills dataDesc with the requested menu property.
- -----------------------------------------------------------------------**)
-
- FUNCTION GetMenuItemProperty(VAR theObjToken:AEDesc; VAR dataDesc:AEDesc):OSErr;
- VAR
- theErr : OSErr;
- theName : Str255;
- theMenuItemPropToken : MenuItemPropToken;
- newDesc : AEDesc;
- tokenSize : Size;
-
- BEGIN
- theErr := AECoerceDesc(theObjToken, typeMyItemProp, newDesc);
- IF (theErr=noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- Ptr(@theMenuItemPropToken),
- sizeof(theMenuItemPropToken),
- tokenSize);
-
- theErr := AEDisposeDesc(newDesc);
- END
- ELSE
- BEGIN
- GetMenuItemProperty:=theErr;
- Exit(GetMenuItemProperty);
- END;
-
- theErr := kAEGenericErr;
-
- IF (theMenuItemPropToken.theItemProp = pName) THEN
- BEGIN
- GetItem(theMenuItemPropToken.theItemToken.theMenuToken.theTokenMenu,
- theMenuItemPropToken.theItemToken.theTokenItem,
- theName);
- theErr := AECreateDesc(typeChar,
- Ptr(@theName[1]),
- length(theName),
- dataDesc);
- END;
-
- IF (theMenuItemPropToken.theItemProp = pItemNumber) THEN
- BEGIN
- theErr := AECreateDesc(typeShortInteger,
- Ptr(@theMenuItemPropToken.theItemToken.theTokenItem),
- sizeof(theMenuItemPropToken.theItemToken.theTokenItem),
- dataDesc);
- END;
-
- GetMenuItemProperty := theErr;
- END; (* GetMenuItemProperty *)
-
- {* -----------------------------------------------------------------------
- Name: HandleGetData
- Purpose: Coerces theObj into a token which we understand and
- extracts the data requested in the token and puts it
- into dataDesc.
- -----------------------------------------------------------------------*}
-
- FUNCTION HandleGetData(theObj: AEDesc; whatType: DescType; VAR dataDesc: AEDesc): OSErr;
- VAR myErr : OSErr;
- newDesc : AEDesc;
- theTextToken : textToken;
- tokenSize : Size;
- theDoc : DPtr;
- objTokenDesc : AEDesc;
-
- BEGIN
- myErr:= errAEWrongDataType;
- (*
- Resolve theObj into an AEDesc which will contain something we understand
- - i.e. One of our internal token types
- *)
-
- myErr:= AEResolve(theObj ,kAEIDoMinimum, objTokenDesc);
-
- IF (myErr=noErr) THEN
-
- IF (objTokenDesc.descriptorType = typeMyApplProp) THEN
- myErr := GetApplicationProperty(objTokenDesc, dataDesc)
- ELSE
-
- IF (objTokenDesc.descriptorType = typeMyMenuProp) THEN
- myErr := GetMenuProperty(objTokenDesc, dataDesc)
- ELSE
-
- IF (objTokenDesc.descriptorType = typeMyItemProp) THEN
- myErr := GetMenuItemProperty(objTokenDesc, dataDesc)
- ELSE
-
- IF (objTokenDesc.descriptorType = typeMyTextProp) THEN
- myErr := GetTextProperty(objTokenDesc, dataDesc)
- ELSE
-
- IF (objTokenDesc.descriptorType = typeMyWindowProp) THEN
- myErr := GetWindowProperty(objTokenDesc, dataDesc)
- ELSE
- IF (objTokenDesc.descriptorType = typeMyText) THEN
- BEGIN
- IF (AECoerceDesc(theObj,typeMyText,newDesc) = noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theTextToken,
- SizeOf(theTextToken),
- tokenSize);
-
- myErr := AEDisposeDesc(newDesc);
-
- theDoc := DPtrFromWindowPtr(theTextToken.tokenWindow);
-
- myErr := BuildStyledTextDesc( theDoc^.theText,
- theTextToken.tokenOffset,
- theTextToken.tokenLength,
- dataDesc);
- END;
- END
- ELSE
- myErr := kAEGenericErr;
-
- HandleGetData := myErr;
- END; { HandleGetData }
-
- {* -----------------------------------------------------------------------
- Name: DoGetData
- Purpose: Handles the GetData AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION DoGetData(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- tempErr : OSErr;
- myDirObj : AEDesc;
- myDataDesc : AEDesc;
- actualSize : Size;
- returnedType: DescType;
- reqType : DescType;
-
- BEGIN
- myDataDesc.dataHandle := nil;
- myDirObj.dataHandle := nil;
-
- (*
- extract the direct object, which is the object whose data is to be returned
- *)
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- (*
- now the get the type of data wanted - optional
- *)
-
- tempErr := AEGetParamPtr( theAppleEvent,
- keyAERequestedType,
- typeType,
- returnedType,
- @reqType,
- SizeOf(reqType),
- actualSize);
-
- IF (tempErr<>noErr) THEN
- reqType := typeChar;
-
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { get the data }
- IF (myErr = noErr) THEN
- myErr := HandleGetData(myDirObj, reqType, myDataDesc);
-
- { if they wanted a reply, attach it now }
- IF (myErr=noErr) THEN
- IF (reply.descriptorType <> typeNull) THEN
- myErr := AEPutParamDesc(reply, keyDirectObject, myDataDesc);
-
- IF (myDataDesc.dataHandle<>NIL) THEN
- tempErr := AEDisposeDesc(myDataDesc);
-
- IF (myDirObj.dataHandle<>NIL) THEN
- tempErr := AEDisposeDesc(myDirObj);
-
- DoGetData := myErr;
- END; { DoGetData }
-
-
- {* -----------------------------------------------------------------------
- Name: DoGetDataSize
- Purpose: Handles the GetDataSize AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION DoGetDataSize(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- tempErr : OSErr;
- myDirObj : AEDesc;
- myDataDesc : AEDesc;
- actualSize : Size;
- returnedType: DescType;
- reqType : DescType;
- dataSize : longInt;
-
- BEGIN
- myDataDesc.dataHandle := nil;
- myDirObj.dataHandle := nil;
-
- { pick up the direct object, which is the object whose data is to be sized }
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- { now the get the type wanted - optional}
-
- tempErr := AEGetParamPtr( theAppleEvent,
- keyAERequestedType,
- typeType,
- returnedType,
- @reqType,
- SizeOf(reqType),
- actualSize);
-
- IF (tempErr<>noErr) THEN
- reqType := typeChar;
-
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { get the data }
- IF (myErr = noErr) THEN
- myErr := HandleGetData(myDirObj, reqType, myDataDesc);
-
- { evaluate size of data and discard, create desc for size }
- IF (myErr = noErr) THEN
- IF (myDataDesc.dataHandle<>NIL) THEN
- BEGIN
- dataSize := GetHandleSize(Handle(myDataDesc.dataHandle));
- DisposHandle(Handle(myDataDesc.dataHandle));
- myErr := AECreateDesc(typeLongInteger,
- @dataSize,
- sizeOf(dataSize),
- myDataDesc);
- END;
-
-
- { if they wanted a reply, attach it now }
-
- IF (myErr=noErr) THEN
- IF (reply.descriptorType <> typeNull) THEN
- myErr := AEPutParamDesc(reply, keyDirectObject, myDataDesc);
-
- { discard our copy }
-
- IF (myDataDesc.dataHandle<>NIL) THEN
- tempErr := AEDisposeDesc(myDataDesc);
-
- IF (myDirObj.dataHandle<>NIL) THEN
- tempErr := AEDisposeDesc(myDirObj);
-
- DoGetDataSize := myErr;
- END; { DoGetDataSize }
-
- {* -----------------------------------------------------------------------
- Name: DoNewElement
- Purpose: Handles the NewElement AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION DoNewElement(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
-
- {
- Create New Windows - or error
- }
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- returnedType : DescType;
- newElemClass : DescType;
- actSize : Size;
- wndwObjSpec : AEDesc;
- theDoc : DPtr;
-
- BEGIN
- wndwObjSpec.dataHandle := NIL;
-
- myErr := AEGetParamPtr( theAppleEvent,
- keyAEObjectClass,
- typeType,
- returnedType,
- @newElemClass,
- SizeOf(newElemClass),
- actSize);
-
- { check for missing required parameters }
-
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { got all required params }
-
- { let's make sure container is the null desc }
- { and they want a window }
-
- IF (newElemClass <> cWindow) THEN
- myErr := errAEWrongDataType;
-
- { let's create a new window }
-
- IF (myErr = noErr) THEN
- theDoc := NewDocument(FALSE);
-
- IF (myErr = noErr) THEN
- IF (theDoc = NIL) THEN
- myErr := -1700
- ELSE
- BEGIN
- ShowWindow(theDoc^.theWindow);
- theDoc^.dirty := FALSE;
-
- myErr := MakeWindowObj(theDoc^.theWindow,
- wndwObjSpec);
- END;
-
- IF (myErr = noErr) THEN
- IF (reply.descriptorType <> typeNull) THEN
- myErr := AEPutParamDesc(reply,
- keyDirectObject,
- wndwObjSpec);
-
- IF (wndwObjSpec.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(wndwObjSpec);
-
- DoNewElement := myErr;
- END; { DoNewElement }
-
- {* -----------------------------------------------------------------------
- Name: DoIsThereA
- Purpose: Handles the IsThereA AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION DoIsThereA(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
-
- {
- Support check of Windows at first
-
- What we do :
- Get Direct Object
- Check have all required params
- Coerce into things we support
- if we get something back
- check to see it exists and set reply
- clean up
- return
- }
-
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- myDirObject : AEDesc;
- windDesc : AEDesc;
- dataDesc : AEDesc;
- theWindowToken: WindowToken;
- tokenSize : Size;
- exists : Boolean;
-
- BEGIN
- myErr := noErr;
-
- myDirObject.dataHandle := NIL;
- windDesc.dataHandle := NIL;
- dataDesc.dataHandle := NIL;
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObject);
-
- { check for missing required parameters }
-
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { got all required params }
-
- { let's make sure they want to check for a window }
-
- exists := FALSE;
-
- IF (myErr = noErr) THEN
- IF (AECoerceDesc(myDirObject,typeMyWndw,windDesc) = noErr) THEN
- IF (windDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor(windDesc,
- @theWindowToken,
- SizeOf(theWindowToken),
- tokenSize);
-
- exists := (theWindowToken <> NIL);
- END;
-
- IF (myErr = noErr) THEN
- myErr := AECreateDesc(typeBoolean,
- @exists,
- sizeof(exists),
- dataDesc);
-
-
- {
- if they wanted a reply, which they surely must,
- attach the result to it…
- }
-
- IF (myErr = noErr) THEN
- IF (reply.descriptorType <> typeNull) THEN
- myErr := AEPutParamDesc(reply,
- keyDirectObject,
- dataDesc);
-
- IF (dataDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(dataDesc);
-
- IF (myDirObject.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(myDirObject);
-
- IF (windDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(windDesc);
-
- DoIsThereA := myErr;
- END; { DoIsThereA }
-
- {* -----------------------------------------------------------------------
- Name: DoCloseWindow
- Purpose: Handles the Close AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION DoCloseWindow( theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- tempErr : OSErr;
- myDirObj : AEDesc;
- newDesc : AEDesc;
- theWindowToken : windowToken;
- tokenSize : Size;
- saveOpt : DescType;
- actSize : Size;
- returnedType : DescType;
- theDoc : DPtr;
-
- BEGIN
- myDirObj.dataHandle := nil;
-
- { pick up the direct object, which is the object (window) to close }
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- { pick up optional save param, if any }
-
- saveOpt := kAEAsk; { the default }
-
- tempErr := AEGetParamPtr(theAppleEvent,
- keyAESaveOptions,
- typeEnumerated,
- returnedType,
- @saveOpt,
- SizeOf(saveOpt),
- actSize);
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { get the window to close as a window ptr }
- IF (myErr = noErr) THEN
- IF (AECoerceDesc(myDirObj,typeMyWndw,newDesc) = noErr) THEN
- IF (newDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theWindowToken,
- SizeOf(theWindowToken),
- tokenSize);
-
- myErr := AEDisposeDesc(newDesc);
-
- IF (theWindowToken<>NIL) THEN
- BEGIN
- myErr:=AESetInteractionAllowed(kAEInteractWithAll); (* Should do this in prefs *)
-
- (*
- We do some of the close checks here to avoid
- calling AEInteractWithUser
- *)
- theDoc := DPtrFromWindowPtr(theWindowToken);
-
- IF (theDoc^.dirty) OR
- (theDoc^.everSaved=false) THEN
- IF (saveOpt <> kAENo) THEN
- BEGIN
- myErr := AEInteractWithUser(kAEDefaultTimeOut,
- NIL,
- NIL);
- END;
-
- IF myErr=noErr THEN
- myErr := DoClose(theWindowToken, TRUE, saveOpt);
- END
- ELSE
- myErr:= errAEIllegalIndex;
- END;
-
- IF (myDirObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(myDirObj);
-
- DoCloseWindow := myErr;
- END; { DoCloseWindow }
-
- {* -----------------------------------------------------------------------
- Name: DoSaveWindow
- Purpose: Handles the Save AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION DoSaveWindow(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- tempErr : OSErr;
- myDirObj : AEDesc;
- newDesc : AEDesc;
- theWindowToken : windowToken;
- tokenSize : Size;
- actSize : Size;
- returnedType : DescType;
- theDoc : DPtr;
- destFSSpec : FSSpec;
-
- BEGIN
- myDirObj.dataHandle := NIL;
-
- { pick up the direct object, which is the window to save }
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
- { pick up optional destination param, if any }
-
- tempErr := AEGetParamPtr(theAppleEvent,
- keyAEDestination,
- typeFSS,
- returnedType,
- @destFSSpec,
- SizeOf(destFSSpec),
- actSize);
-
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { get the data }
-
- myErr := AECoerceDesc(myDirObj,typeMyWndw,newDesc);
-
- IF (myErr = noErr) THEN
- IF (newDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theWindowToken,
- SizeOf(theWindowToken),
- tokenSize);
-
- myErr := AEDisposeDesc(newDesc);
-
- IF (theWindowToken<>NIL) THEN
- BEGIN
- theDoc := DPtrFromWindowPtr(theWindowToken);
-
- IF (theDoc^.everSaved = false) THEN
- IF (tempErr<>noErr) THEN
- (* We had no supplied destination and no default either *)
- myErr := kAEGenericErr;
-
- IF (myErr=noErr) THEN
- IF (tempErr=noErr) THEN
- BEGIN (* we were told where *)
- myErr := DoSave(theDoc, destFSSpec);
-
- IF (myErr=noErr) THEN
- AssocAllSections(theDoc);
- END
- ELSE
- myErr := SaveUsingTemp(theDoc);
- END
- ELSE
- myErr:= errAEIllegalIndex;
- END;
-
- DoSaveWindow := myErr;
-
- IF (myDirObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(myDirObj);
-
- END; { DoSaveWindow }
-
- {* -----------------------------------------------------------------------
- Name: DoRevertWindow
- Purpose: Handles the Revert AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION DoRevertWindow(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- myDirObj : AEDesc;
- newDesc : AEDesc;
- theWindowToken : windowToken;
- tokenSize : Size;
- theDoc : DPtr;
-
- BEGIN
- myDirObj.dataHandle := NIL;
-
- { pick up the direct object, which is the window to save }
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- IF (myErr = noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- { get the window to revert from the direct object }
-
- myErr := AECoerceDesc(myDirObj,typeMyWndw,newDesc);
-
- IF (myErr = noErr) THEN
- IF (newDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theWindowToken,
- SizeOf(theWindowToken),
- tokenSize);
-
- myErr := AEDisposeDesc(newDesc);
-
- IF (theWindowToken<>NIL) THEN
- BEGIN
- theDoc := DPtrFromWindowPtr(theWindowToken);
-
- HidePen;
- TESetSelect(0, theDoc^.theText^^.teLength, theDoc^.theText);
- ShowPen;
- TEDelete(theDoc^.theText);
-
- IF (theDoc^.everSaved) THEN
- BEGIN
- myErr := GetFileContents(theDoc^.theFSSpec, theDoc);
- IF (myErr = noErr) THEN
- BEGIN
- ResizeWindow(theDoc);
- theDoc^.dirty := FALSE;
- END;
- END;
-
- ShowWindow(theDoc^.theWindow); (* <<< Visible already??? *)
- DoUpdate(theDoc);
- END
- ELSE
- myErr:= errAEIllegalIndex;
- END;
-
- IF (myDirObj.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(myDirObj);
-
- DoRevertWindow := myErr;
- END; { DoRevertWindow }
-
- {*-----------------------------------------------------------------------
- Name: DoPrintDocuments
- Purpose: Print a list of documents (or windows).
- -----------------------------------------------------------------------*}
- FUNCTION DoPrintDocuments( message, reply: AppleEvent; refcon: LONGINT ): OSErr;
- VAR
- index : LONGINT;
- itemsInList : LONGINT;
- keywd : AEKeyWord;
- err : OSErr;
- docList : AEDescList;
- actSize : Size;
- typeCode : DescType;
- theFSSpec : FSSpec;
- theWindowToken : WindowToken;
- forgetErr : OSErr;
- talkToUser : Boolean;
-
- BEGIN
- err := AEGetParamDesc(message, keyDirectObject, typeAEList, docList) ;
- err := AECountItems( docList, itemsInList) ;
-
- FOR index := 1 TO itemsInList DO
- IF (err = noErr) THEN
- BEGIN
- forgetErr := AEGetNthPtr( docList, index, typeFSS, keywd, typeCode,
- @theFSSpec, sizeof(theFSSpec), actSize);
-
- IF (forgetErr = noErr) THEN
- BEGIN
- IF (err = noErr) THEN
- err := IssueAEOpenDoc(theFSSpec);
-
- IF (err = noErr) THEN
- IssuePrintWindow(FrontWindow);
-
- IF (err = noErr) THEN
- IssueCloseCommand(FrontWindow);
- END
- ELSE
- BEGIN (* wasn't a file - was it a window ? *)
- err := AEGetNthPtr( docList, index, typeMyWndw, keywd, typeCode,
- @theWindowToken, sizeof(windowToken), actSize);
-
- talkToUser := (AEInteractWithUser(kAEDefaultTimeOut, NIL, NIL) = noErr);
-
- IF (err = noErr) THEN
- PrintWindow(DPtrFromWindowPtr(theWindowToken), talkToUser);
- END
- END;
-
- IF (docList.dataHandle<>NIL) THEN
- forgetErr := AEDisposeDesc(docList);
-
- DoPrintDocuments := err;
- END; (* DoPrintDocuments *)
-
- {*-----------------------------------------------------------------------
- Name: HandleCreatePub
- Purpose: Create a publisher.
- -----------------------------------------------------------------------*}
- FUNCTION HandleCreatePub( theAppleEvent, reply: AppleEvent; refcon: LONGINT ): OSErr;
- VAR
- myErr : OSErr;
- theFSSpec : FSSpec;
- forgetErr : OsErr;
- forget2Err : OsErr;
- myDirObj : AEDesc;
- myFileLoc : AEDesc;
- theTextToken : TextToken;
- theDoc : DPtr;
- newDesc : AEDesc;
- tokenSize : LongInt;
- haveFSSpec : BOOLEAN;
-
- BEGIN
- myErr := noErr;
-
- forgetErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- forget2Err := AEGetParamDesc(theAppleEvent,
- keyAEEditionFileLoc,
- typeWildCard,
- myFileLoc);
-
- IF (myErr=noErr) THEN
- myErr := GotRequiredParams(theAppleEvent);
-
- IF (forgetErr=noErr) THEN (* Set the selection to the supplied object - if any *)
- BEGIN
- forgetErr := AECoerceDesc(myDirObj,typeMyText,newDesc);
- IF (newDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theTextToken,
- SizeOf(theTextToken),
- tokenSize);
-
- theDoc := DPtrFromWindowPtr(theTextToken.tokenWindow);
-
- TESetSelect(theTextToken.tokenOffset-1,
- theTextToken.tokenOffset+
- theTextToken.tokenLength-1,
- theDoc^.theText);
-
- forgetErr := AEDisposeDesc(newDesc);
- END;
- END
- ELSE
- theDoc := DPtrFromWindowPtr(FrontWindow);
-
- IF (theDoc=NIL) THEN
- BEGIN
- (* Should clean up and exit with error *)
- END;
-
- haveFSSpec := FALSE;
-
- IF (forget2Err=noErr) THEN (* Get the Edition Container File *)
- BEGIN
- forget2Err := AECoerceDesc(myDirObj,typeFSS,newDesc);
- IF (newDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theFSSpec,
- SizeOf(theFSSpec),
- tokenSize);
- forget2Err := AEDisposeDesc(newDesc);
- haveFSSpec := TRUE;
- END;
- END;
-
- IF (NOT haveFSSpec) THEN
- myErr := GetEditionContainer(theDoc, theFSSpec);
-
- IF (myErr = noErr) THEN
- myErr := PublishText(theDoc, @theFSSpec);
-
- IF (myDirObj.dataHandle<>NIL) THEN
- forgetErr := AEDisposeDesc(myDirObj);
-
- IF (myFileLoc.dataHandle<>NIL) THEN
- forgetErr := AEDisposeDesc(myFileLoc);
-
- HandleCreatePub := myErr;
-
- END; (* HandleCreatePub *)
-
-
- FUNCTION MyCountProc( desiredType : DescType;
- containerClass: DescType;
- container : AEDesc;
- VAR result : LongInt): OSErr; FORWARD;
-
- {* -----------------------------------------------------------------------
- Name: HandleNumberOfElements
- Purpose: Handles the Number Of Elements AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION HandleNumberOfElements(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR myErr : OSErr;
- myDirObj : AEDesc;
- myClass : DescType;
- myCount : LongInt;
- returnedType : DescType;
- actSize : Size;
-
- BEGIN
- myErr := errAEEventNotHandled;
- myDirObj.dataHandle := NIL;
-
- { pick up direct object, which is the container in which things are to be counted }
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- { now the class of objects to be counted }
-
- myErr := AEGetParamPtr(theAppleEvent,
- keyAEObjectClass,
- typeType,
- returnedType,
- @myClass,
- SizeOf(myClass),
- actSize);
-
- { missing any parameters? }
-
- myErr := GotRequiredParams(theAppleEvent);
-
- { now count }
-
- IF (myErr = noErr) THEN
- myErr := MyCountProc(myClass,myDirObj.descriptorType,myDirObj,myCount);
-
- { add result to reply }
-
- IF (myErr = noErr) THEN
- IF reply.descriptorType <> typeNull THEN
- myErr := AEPutParamPtr(reply,
- keyDirectObject,
- typeLongInteger,
- @myCount,
- SizeOf(myCount));
- IF (myErr = noErr) THEN
- myErr := AEDisposeDesc(myDirObj);
-
- HandleNumberOfElements := myErr;
-
- END; { HandleNumberOfElements }
-
- {* -----------------------------------------------------------------------
- Name: HandleShowSelection
- Purpose: Handles the Make Selection Visible AppleEvent.
- -----------------------------------------------------------------------*}
-
- FUNCTION HandleShowSelection(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR myErr : OSErr;
- ignoreErr : OSErr;
- myDirObj : AEDesc;
- newDesc : AEDesc;
- tokenDesc : AEDesc;
- actSize : Size;
- theWindowToken: WindowToken;
- theDocument : DPtr;
- theHTE : TEHandle;
-
- BEGIN
- myDirObj.dataHandle := NIL;
- tokenDesc.dataHandle := NIL;
-
- (*
- pick up direct object, i.e. the window in which to show the selection
- *)
-
- myErr := AEGetParamDesc(theAppleEvent,
- keyDirectObject,
- typeWildCard,
- myDirObj);
-
- (*
- missing any parameters?
- *)
-
- myErr := GotRequiredParams(theAppleEvent);
-
- (*
- convert object to windowToken which we understand
- *)
-
- myErr := AEResolve(myDirObj, kAEIDoMinimum, tokenDesc);
-
- IF (myErr = noErr) THEN
- IF (tokenDesc.descriptorType=typeMyWndw) THEN
- BEGIN
- IF (AECoerceDesc(myDirObj,typeMyWndw,newDesc) = noErr) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theWindowToken,
- SizeOf(theWindowToken),
- actSize);
-
- IF (newDesc.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(newDesc);
-
- IF (myErr=noErr) THEN
- IF (theWindowToken<>NIL) THEN
- ShowSelect(DPtrFromWindowPtr(theWindowToken))
- ELSE
- myErr := errAEIllegalIndex;
-
- END;
- END
- ELSE
- IF (tokenDesc.descriptorType=typeMyText) THEN
- BEGIN
- myErr := SetSelectionOfAppleEventObject(keyDirectObject,
- theAppleEvent,
- theDocument,
- theHTE);
- IF (theDocument<>NIL) THEN
- ShowSelect(theDocument)
- ELSE
- myErr := errAEIllegalIndex;
- END
- ELSE
- myErr := errAEEventNotHandled;
-
- IF (myDirObj.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(myDirObj);
-
- IF (tokenDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(tokenDesc);
-
- HandleShowSelection := myErr;
-
- END; { HandleShowSelection }
-
- FUNCTION HandleStartRecording(theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- VAR myErr : OSErr;
-
- BEGIN
- gBigBrother := gBigBrother +1;
-
- myErr := GotRequiredParams(theAppleEvent);
-
- HandleStartRecording := noErr;
- END; { HandleStartRecording }
-
- FUNCTION HandleStopRecording( theAppleEvent : AppleEvent;
- reply : AppleEvent;
- handlerRefCon : LongInt): OSErr;
- BEGIN
- gBigBrother := gBigBrother -1;
- HandleStopRecording := noErr;
- END; { HandleStopRecording }
-
- {$AECommandIssuers}
-
- {*****************************************************************************}
- {
- Start of section involved in building and sending AppleEvent Objects as/with
- commands
- }
-
- (*
- Make an AEDesc that describes the selection in the window and text edit
- record supplied
- *)
-
- FUNCTION MakeWindowObj( theWindow : WindowPtr;
- VAR dMyDoc : AEDesc):OSErr;
- VAR dNull : AEDesc;
- dDocName : AEDesc;
- windowName : Str255;
- myErr : OSErr;
-
- BEGIN
- GetWTitle(theWindow,windowName);
- myErr := AECreateDesc(typeChar,Pointer(ORD4(@windowName)+1), length(windowName), dDocName);
-
- if (myErr=noErr) THEN
- myErr := AECreateDesc(typeNull, nil , 0, dNull);
-
- if (myErr=noErr) THEN
- myErr := CreateObjSpecifier(cWindow, dNull, formName, dDocName, TRUE, dMyDoc);
-
- MakeWindowObj:= myErr;
-
- END; (*MakeWindowObj*)
-
- FUNCTION MakeTextObj( theWindow : WindowPtr;
- selStart : INTEGER;
- selEnd : INTEGER;
- VAR selTextObj : AEDesc): OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- dMyDoc : AEDesc;
- startOfs : AEDesc;
- endOfs : AEDesc;
- startObj : AEDesc;
- endObj : AEDesc;
- rangeDesc : AEDesc;
- startChar : LongInt;
- endChar : LongInt;
- spotFlag : BOOLEAN;
-
- BEGIN
- myErr := noErr;
-
- IF (theWindow=nil) THEN
- BEGIN
- MakeTextObj:=noErr;
- Exit(MakeTextObj);
- END;
-
- selTextObj.dataHandle := nil;
- dMyDoc.dataHandle := nil;
- startObj.dataHandle := nil;
- endObj.dataHandle := nil;
-
- (*
- make the window object
- *)
-
- myErr := MakeWindowObj(theWindow, dMyDoc);
-
- IF (myErr=noErr) THEN
- BEGIN
- { get the start and end of selection }
-
- startChar := selStart+1; { start counting obj's from 1, not 0 }
- endChar := selEnd;
- spotFlag := (selStart = selEnd);
-
- myErr := CreateOffsetDescriptor(startChar, startOfs);
-
- IF myErr=noErr THEN
- IF spotFlag THEN
- myErr := CreateObjSpecifier( cSpot,
- dMyDoc,
- formAbsolutePosition,
- startOfs,
- TRUE,
- selTextObj)
- ELSE
- BEGIN
- { not a spot - must represent as range }
- { make obj for start char }
- myErr := CreateObjSpecifier(cChar, dMyDoc, formAbsolutePosition, startOfs, FALSE, startObj);
-
- IF (myErr=noErr) THEN
- myErr := CreateOffsetDescriptor(endChar, endOfs);
-
- IF (myErr=noErr) THEN
- myErr := CreateObjSpecifier(cChar, dMyDoc, formAbsolutePosition, endOfs, FALSE, endObj);
-
- IF (myErr=noErr) THEN
- myErr := CreateRangeDescriptor(startObj,
- endObj,
- FALSE,
- rangeDesc);
-
- if (myErr=noErr) then
- BEGIN
- myErr := CreateObjSpecifier(cChar,
- dMyDoc,
- formRange,
- rangeDesc,
- TRUE,
- selTextObj);
-
- END;
-
- IF (startObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(startObj);
-
- IF (endObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(endObj);
-
- IF (startOfs.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(startOfs);
-
- IF (endOfs.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(endOfs);
- END;
- END;
-
- MakeTextObj := myErr;
- END; { MakeTextObj }
-
- FUNCTION MakeSelectedTextObj(theWindow : WindowPtr;
- theTextEditHandle : TEHandle;
- VAR selTextObj : AEDesc) : OSErr;
- BEGIN
- MakeSelectedTextObj:= MakeTextObj(theWindow,
- theTextEditHandle^^.selStart,
- theTextEditHandle^^.selEnd,
- selTextObj);
-
- END; (* MakeSelectedTextObj *)
-
- TYPE editCommandType = (editCutCommand, editCopyCommand, editPasteCommand, editClearCommand);
-
- PROCEDURE DoEditCommand(theDocument:DPtr; whatCommand : editCommandType);
- VAR err : OSErr;
- forgetErr : OSErr;
- ourAddress : AEAddressDesc;
- editCommandEvent : AppleEvent;
- ignoreReply : AppleEvent;
- ourTextSelObj : AEDesc;
- theEventID : AEEventID;
- theEventClass : AEEventClass;
-
- BEGIN
- (*
- Initialise
- *)
- ourAddress.dataHandle := nil;
- ourTextSelObj.dataHandle := nil;
- editCommandEvent.dataHandle := nil;
- ignoreReply.dataHandle := nil;
-
- err := MakeSelfAddress(ourAddress);
-
- (*
- Build an object to represent the current document's selection
- *)
- err := MakeSelectedTextObj(theDocument^.theWindow, theDocument^.theText,ourTextSelObj);
-
- IF (err=noErr) THEN
- BEGIN
- CASE whatCommand OF
- editCutCommand : BEGIN
- theEventID := kAECut;
- theEventClass := kAEMiscStandards;
- END;
- editCopyCommand : BEGIN
- theEventID := kAECopy;
- theEventClass := kAEMiscStandards;
- END;
- editPasteCommand: BEGIN
- theEventID := kAEPaste;
- theEventClass := kAEMiscStandards;
- END;
- editClearCommand: BEGIN
- theEventID := kAEDelete;
- theEventClass := kAECoreSuite;
- END;
- END;
-
- err := AECreateAppleEvent( theEventClass, theEventID, ourAddress, 0, 0, editCommandEvent);
-
- { add parameter }
- IF (err=noErr) THEN
- err := AEPutParamDesc(editCommandEvent,keyDirectObject,ourTextSelObj);
-
- {and now Send the message}
- IF (err=noErr) THEN
- err := AESend(editCommandEvent,ignoreReply,kAENoReply,KAEHighPriority,10000,nil, nil);
- END;
-
- (*
- Clean up
- *)
- if (ourAddress.dataHandle<>nil) then
- err := AEDisposeDesc(ourAddress);
-
- if (editCommandEvent.dataHandle<>nil) then
- err := AEDisposeDesc(editCommandEvent);
-
- if (ignoreReply.dataHandle<>nil) then
- err := AEDisposeDesc(ignoreReply);
-
- if (ourTextSelObj.dataHandle<>nil) then
- err := AEDisposeDesc(ourTextSelObj);
-
- END; (*DoEditCommand*)
-
- PROCEDURE IssueCutCommand(theDocument:DPtr);
- BEGIN
- DoEditCommand(theDocument, editCutCommand);
- END;
-
- PROCEDURE IssueCopyCommand(theDocument:DPtr);
- BEGIN
- DoEditCommand(theDocument, editCopyCommand);
- END;
-
- PROCEDURE IssuePasteCommand(theDocument:DPtr);
- BEGIN
- DoEditCommand(theDocument, editPasteCommand);
- END;
-
- PROCEDURE IssueClearCommand(theDocument:DPtr);
- BEGIN
- DoEditCommand(theDocument, editClearCommand);
- END;
-
- PROCEDURE IssueFontCommand(theDocument:DPtr;theItem:INTEGER);
- VAR name : Str255;
- strDesc : AEDesc;
- theAddress : AEAddressDesc;
- selTextObj : AEDesc;
- err : OSErr;
-
- BEGIN
- err := MakeSelfAddress(theAddress);
-
- err := MakeSelectedTextObj(theDocument^.theWindow, theDocument^.theText, selTextObj);
-
- GetItem(myMenus[fontM], theItem, name);
-
- IF (err=noErr) THEN
- err := AECreateDesc(typeChar,
- POINTER(ORD4(@name)+1),
- Length(name),
- strDesc);
-
- IF (err=noErr) THEN
- err := SendAESetObjProp(selTextObj,
- pFont,
- strDesc,
- theAddress);
- END; (* IssueFontCommand *)
-
- (*
- Window property routines
- *)
-
- PROCEDURE IssueZoomCommand(whichWindow:WindowPtr; whichPart:INTEGER);
- VAR zoomBool : Boolean;
- zoomDesc : AEDesc;
- selfAddr : AEAddressDesc;
- frontWinObj : AEDesc;
- err : OSErr;
-
- BEGIN
- err := MakeSelfAddress(selfAddr);
-
- err := MakeWindowObj(whichWindow, frontWinObj);
-
- zoomBool := (whichPart=inZoomOut);
-
- err := AECreateDesc(typeBoolean,
- @zoomBool,
- sizeOf(zoomBool),
- zoomDesc);
-
- err := SendAESetObjProp(frontWinObj,
- pIsZoomed,
- zoomDesc,
- selfAddr);
- END; (* IssueZoomCommand *)
-
- PROCEDURE IssueCloseCommand(whichWindow:WindowPtr);
- VAR selfAddr : AEAddressDesc;
- frontWinObj : AEDesc;
- err : OSErr;
- ignoreErr : OSErr;
- closeCommandEvent : AppleEvent;
- ignoreReply : AppleEvent;
-
- BEGIN
-
- frontWinObj.dataHandle:=NIL;
-
- err := MakeSelfAddress(selfAddr);
-
- err := MakeWindowObj(whichWindow, frontWinObj);
-
- err := AECreateAppleEvent( kAECoreSuite, kAEClose, selfAddr, 0, 0, closeCommandEvent) ;
-
- { add parameter - the window to close }
- IF (err=noErr) THEN
- err := AEPutParamDesc(closeCommandEvent,keyDirectObject,frontWinObj);
-
- IF (err=noErr) THEN
- err := AESend(closeCommandEvent,ignoreReply,kAENoReply+kAEAlwaysInteract,KAEHighPriority,10000,nil, nil);
-
- IF (closeCommandEvent.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(closeCommandEvent);
-
- IF (selfAddr.dataHandle<>NIL) THEN
- err := AEDisposeDesc(selfAddr);
-
- IF (frontWinObj.dataHandle<>NIL) THEN
- err := AEDisposeDesc(frontWinObj);
-
- END; (* IssueCloseCommand *)
-
- PROCEDURE IssueSizeWindow(whichWindow:WindowPtr; newHSize:INTEGER; newVSize:INTEGER);
- VAR sizeRect : Rect;
- contentRect : Rect;
- edgeSize : INTEGER;
- sizeDesc : AEDesc;
- selfAddr : AEAddressDesc;
- frontWinObj : AEDesc;
- err : OSErr;
-
- BEGIN
- sizeRect := WindowPeek(whichWindow)^.strucRgn^^.rgnBBox;
- contentRect := WindowPeek(whichWindow)^.contRgn^^.rgnBBox;
-
- edgeSize := sizeRect.right-sizeRect.left-(contentRect.right-contentRect.left);
- sizeRect.right := sizeRect.left+newHSize+edgeSize;
-
- edgeSize := sizeRect.bottom-sizeRect.top-(contentRect.bottom-contentRect.top);
- sizeRect.bottom := sizeRect.top+newVSize+edgeSize;
-
- err := MakeSelfAddress(selfAddr);
-
- err := MakeWindowObj(whichWindow, frontWinObj);
-
- IF (err=noErr) THEN
- err := AECreateDesc(typeQDRectangle,
- @sizeRect,
- sizeOf(sizeRect),
- sizeDesc);
-
- IF (err=noErr) THEN
- err := SendAESetObjProp(frontWinObj,
- pBounds,
- sizeDesc,
- selfAddr);
- END; (*IssueSizeWindow*)
-
- PROCEDURE IssueMoveWindow(whichWindow:windowPtr; sizeRect:Rect);
- VAR sizeDesc : AEDesc;
- selfAddr : AEAddressDesc;
- frontWinObj : AEDesc;
- err : OSErr;
-
- BEGIN
- err := MakeSelfAddress(selfAddr);
-
- err := MakeWindowObj(whichWindow, frontWinObj);
-
- IF (err=noErr) THEN
- err := AECreateDesc(typeQDRectangle,
- @sizeRect,
- sizeOf(sizeRect),
- sizeDesc);
- IF (err=noErr) THEN
- err := SendAESetObjProp(frontWinObj,
- pBounds,
- sizeDesc,
- selfAddr);
- END; (*IssueMoveWindow*)
-
- PROCEDURE IssuePageSetupWindow(whichWindow:windowPtr; thePageSetup:TPrint);
- VAR sizeDesc : AEDesc;
- selfAddr : AEAddressDesc;
- frontWinObj : AEDesc;
- err : OSErr;
-
- BEGIN
- err := MakeSelfAddress(selfAddr);
-
- err := MakeWindowObj(whichWindow, frontWinObj);
-
- IF (err=noErr) THEN
- err := AECreateDesc(typeTPrint,
- @thePageSetup,
- sizeOf(thePageSetup),
- sizeDesc);
- IF (err=noErr) THEN
- err := SendAESetObjProp(frontWinObj,
- pPageSetup,
- sizeDesc,
- selfAddr);
- END; (*IssuePageSetupWindow*)
-
- PROCEDURE IssueShowBorders(whichWindow:windowPtr; showBorders:BOOLEAN);
- VAR sizeDesc : AEDesc;
- selfAddr : AEAddressDesc;
- frontWinObj : AEDesc;
- err : OSErr;
-
- BEGIN
- err := MakeSelfAddress(selfAddr);
-
- err := MakeWindowObj(whichWindow, frontWinObj);
-
- IF (err=noErr) THEN
- err := AECreateDesc(typeBoolean,
- @showBorders,
- sizeOf(showBorders),
- sizeDesc);
- IF (err=noErr) THEN
- err := SendAESetObjProp(frontWinObj,
- pShowBorders,
- sizeDesc,
- selfAddr);
- END; (*IssueShowBorders*)
-
- PROCEDURE IssuePrintWindow(whichWindow:windowPtr);
- VAR selfAddr : AEAddressDesc;
- frontWinObj : AEDesc;
- err : OSErr;
- ignoreErr : OSErr;
- printCommandEvent : AppleEvent;
- ignoreReply : AppleEvent;
-
- BEGIN
- err := MakeSelfAddress(selfAddr);
-
- err := MakeWindowObj(whichWindow, frontWinObj);
-
- err := AECreateAppleEvent( kCoreEventClass, kAEPrintDocuments, selfAddr, 0, 0, printCommandEvent) ;
-
- {
- add parameter - the window to print
- }
-
- IF (err=noErr) THEN
- err := AEPutParamDesc(printCommandEvent,keyDirectObject,frontWinObj);
-
- IF (err=noErr) THEN
- err := AESend(printCommandEvent,ignoreReply,kAENoReply+kAEAlwaysInteract,KAEHighPriority,10000,nil, nil);
-
- err := AEDisposeDesc(printCommandEvent);
-
- IF (selfAddr.dataHandle<>NIL) THEN
- err := AEDisposeDesc(selfAddr);
-
- IF (frontWinObj.dataHandle<>NIL) THEN
- err := AEDisposeDesc(frontWinObj);
- END; (*IssuePrintWindow*)
-
- FUNCTION IssueAEOpenDoc(myFSSpec: FSSpec):OSErr;
- { send OpenDocs AppleEvent to myself, with a one-element list
- containing the given file spec
-
- NOTES: the core AEOpenDocs event is defined as taking a list of
- aliases (not file specs) as its direct parameter. However,
- we can send the file spec instead and depend on AppleEvents'
- automatic coercion. In fact, we don't really even have to put
- in a list; AppleEvents will coerce a descriptor into a 1-element
- list if called for. In this routine, though, we'll make the
- list for demonstration purposes.
- }
-
- VAR myAppleEvent: AppleEvent;
- defReply : AppleEvent;
- docList : AEDescList;
- selfAddr : AEAddressDesc;
- myErr : OSErr;
-
- BEGIN
- myAppleEvent.dataHandle := NIL;
- docList.dataHandle := NIL;
- selfAddr.dataHandle := NIL;
- defReply.dataHandle := NIL;
-
- {
- Create empty list and add one file spec
- }
- myErr := AECreateList(NIL,0,FALSE,docList);
-
- IF (myErr=noErr) THEN
- myErr := AEPutPtr(docList,1,typeFSS,@myFSSpec,SizeOf(myFSSpec));
-
- {
- Create a self address to send it to
- }
- IF (myErr=noErr) THEN
- myErr := MakeSelfAddress(selfAddr);
-
- IF (myErr=noErr) THEN
- myErr := AECreateAppleEvent(kCoreEventClass,
- kAEOpenDocuments,
- selfAddr,
- kAutoGenerateReturnID,
- kAnyTransactionID,
- myAppleEvent);
-
- {
- Put Params into our event and send it
- }
- IF (myErr = noErr) THEN
- myErr := AEPutParamDesc(myAppleEvent,
- keyDirectObject,
- docList);
-
- myErr := AESend(myAppleEvent,
- defReply,
- kAENoReply+kAEAlwaysInteract,
- kAENormalPriority,
- kAEDefaultTimeOut,
- NIL,
- NIL);
-
- IssueAEOpenDoc := myErr;
-
- IF (selfAddr.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(selfAddr);
-
- IF (myAppleEvent.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(myAppleEvent);
-
- IF (docList.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(docList);
-
- END; { IssueAEOpenDoc }
-
- PROCEDURE IssueAENewWindow;
-
- (*
- send the New Element event to myself with a null container
- *)
-
- VAR myAppleEvent : AppleEvent;
- defReply : AppleEvent;
- selfAddr : AEAddressDesc;
- myErr : OSErr;
- ignoreErr : OSErr;
- elemClass : DescType;
-
- BEGIN
- myAppleEvent.dataHandle := NIL;
-
- (*
- Create the address of us
- *)
-
- myErr := MakeSelfAddress(selfAddr);
-
- (*
- create event
- *)
-
- myErr := AECreateAppleEvent(kAECoreSuite,
- kAECreateElement,
- selfAddr,
- kAutoGenerateReturnID,
- kAnyTransactionID,
- myAppleEvent);
- (*
- attach desired class of new element
- *)
-
- elemClass := cWindow;
-
- IF (myErr = noErr) THEN
- myErr := AEPutParamPtr(myAppleEvent,
- keyAEObjectClass,
- typeType,
- @elemClass,
- SizeOf(elemClass));
-
- (*
- send the event
- *)
-
- IF (myErr = noErr) THEN
- myErr := AESend(myAppleEvent,
- defReply,
- kAENoReply+kAENeverInteract,
- kAENormalPriority,
- kAEDefaultTimeOut,
- NIL,
- NIL);
- (*
- Clean up - reply never created so don't throw away
- *)
- IF (selfAddr.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(selfAddr);
-
- IF (myAppleEvent.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(myAppleEvent);
-
- END; { IssueAENewWindow }
-
- FUNCTION IssueSaveCommand(theWindow : WindowPtr;
- where : FSSpecPtr):OSErr;
- (*
- send an AppleEvent Save Event to myself
- *)
-
- VAR windowObj : AEDesc;
- myAppleEvent : AppleEvent;
- defReply : AppleEvent;
- myErr : OSErr;
- ignoreErr : OSErr;
- selfAddr : AEAddressDesc;
-
- BEGIN
- windowObj.dataHandle := NIL;
- myAppleEvent.dataHandle := NIL;
-
- myErr := MakeWindowObj(theWindow, windowObj);
-
- IF (myErr=noErr) THEN
- myErr := MakeSelfAddress(selfAddr);
-
- (*
- Build event
- *)
-
- IF (myErr = noErr) THEN
- myErr := AECreateAppleEvent(kAECoreSuite,
- kAESave,
- selfAddr,
- kAutoGenerateReturnID,
- kAnyTransactionID,
- myAppleEvent);
-
- (*
- say which window
- *)
-
- IF (myErr=noErr) THEN
- myErr := AEPutParamDesc(myAppleEvent,
- keyDirectObject,
- windowObj);
-
- (*
- add optional file param if we need to
- *)
-
- IF (where<>NIL) THEN
- IF (myErr=noErr) THEN
- myErr := AEPutParamPtr(myAppleEvent,
- keyAEDestination,
- typeFSS,
- @where^,
- SizeOf(where^));
-
- (*
- send the event
- *)
- IF (myErr=noErr) THEN
- myErr := AESend(myAppleEvent,
- defReply,
- kAENoReply+kAENeverInteract,
- kAENormalPriority,
- kAEDefaultTimeOut,
- NIL,
- NIL);
-
- IssueSaveCommand := myErr;
-
- IF (selfAddr.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(selfAddr);
-
- IF (windowObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(windowObj);
-
- IF (myAppleEvent.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(myAppleEvent);
- END; { IssueSaveCommand }
-
- FUNCTION IssueRevertCommand(theWindow : WindowPtr):OSErr;
- (*
- send an AppleEvent Revert Event to myself
- *)
-
- VAR windowObj : AEDesc;
- myAppleEvent : AppleEvent;
- defReply : AppleEvent;
- myErr : OSErr;
- selfAddr : AEAddressDesc;
-
- BEGIN
- windowObj.dataHandle := NIL;
- myAppleEvent.dataHandle := NIL;
-
- myErr := MakeWindowObj(theWindow, windowObj);
-
- IF (myErr=noErr) THEN
- myErr := MakeSelfAddress(selfAddr);
-
- (*
- Build event
- *)
-
- IF (myErr = noErr) THEN
- myErr := AECreateAppleEvent(kAEMiscStandards,
- kAERevert,
- selfAddr,
- kAutoGenerateReturnID,
- kAnyTransactionID,
- myAppleEvent);
- (*
- say which window
- *)
-
- IF (myErr=noErr) THEN
- myErr := AEPutParamDesc(myAppleEvent,
- keyDirectObject,
- windowObj);
- (*
- send the event
- *)
- IF (myErr=noErr) THEN
- myErr := AESend(myAppleEvent,
- defReply,
- kAENoReply+kAENeverInteract,
- kAENormalPriority,
- kAEDefaultTimeOut,
- NIL,
- NIL);
-
- IssueRevertCommand := myErr;
-
- IF (windowObj.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(windowObj);
-
- IF (myAppleEvent.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(myAppleEvent);
-
- IF (selfAddr.dataHandle<>NIL) THEN
- myErr := AEDisposeDesc(selfAddr);
-
- END; { IssueRevertCommand }
-
- (*
- Name : IssueQuitCommand
- Purpose : Sends self a Quit AppleEvent
- *)
- FUNCTION IssueQuitCommand:OSErr;
- VAR
- myAppleEvent : AppleEvent;
- defReply : AppleEvent;
- myErr : OSErr;
- ignoreErr : OSErr;
- selfAddr : AEAddressDesc;
- mySaveOpt : DescType;
-
- BEGIN
- myAppleEvent.dataHandle := nil;
- selfAddr.dataHandle := nil;
-
- myErr := MakeSelfAddress(selfAddr);
-
- (*
- Build event
- *)
-
- IF (myErr = noErr) THEN
- myErr := AECreateAppleEvent(kCoreEventClass,
- kAEQuitApplication,
- selfAddr,
- kAutoGenerateReturnID,
- kAnyTransactionID,
- myAppleEvent);
- (*
- say which save option
- *)
-
- mySaveOpt := kAEAsk;
-
- IF (myErr = noErr) THEN
- myErr := AEPutParamPtr(myAppleEvent,
- keyAESaveOptions,
- typeEnumerated,
- Ptr(@mySaveOpt),
- sizeof(mySaveOpt));
- (*
- send the event
- *)
- IF (myErr=noErr) THEN
- myErr := AESend(myAppleEvent,
- defReply,
- kAENoReply+kAEAlwaysInteract,
- kAENormalPriority,
- kAEDefaultTimeout,
- nil,
- nil);
-
- IF (myAppleEvent.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(myAppleEvent);
-
- IF (selfAddr.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(selfAddr);
-
- IssueQuitCommand := myErr;
- END; (* IssueQuitCommand *)
-
- (*
- Name : IssueCreatePublisher
- Purpose : Interact with user to get Publisher info
- and the IssueAECommand to Publish currect selection
- *)
- PROCEDURE IssueCreatePublisher(whichDoc:DPtr);
- VAR selfAddr : AEAddressDesc;
- selTextObj : AEDesc;
- err : OSErr;
- ignoreErr : OSErr;
- publishCommandEvent : AppleEvent;
- ignoreReply : AppleEvent;
-
- BEGIN
- publishCommandEvent.dataHandle := NIL;
- selfAddr.dataHandle := NIL;
- selTextObj.dataHandle := NIL;
-
- err := MakeSelfAddress(selfAddr);
- IF (err=noErr) THEN
- err := MakeSelectedTextObj(whichDoc^.theWindow, whichDoc^.theText, selTextObj);
-
- err := AECreateAppleEvent( kAEMiscStandards, kAECreatePublisher, selfAddr, 0, 0, publishCommandEvent) ;
-
- {
- add parameter - the text to publish
- }
-
- IF (err=noErr) THEN
- err := AEPutParamDesc(publishCommandEvent,keyDirectObject,selTextObj);
-
- IF (err=noErr) THEN
- err := AESend(publishCommandEvent,ignoreReply,kAENoReply+kAEAlwaysInteract,KAEHighPriority,10000,nil, nil);
-
- IF (publishCommandEvent.dataHandle<>NIL) THEN
- err := AEDisposeDesc(publishCommandEvent);
-
- IF (selTextObj.dataHandle<>NIL) THEN
- err := AEDisposeDesc(selTextObj);
-
- IF (selfAddr.dataHandle<>NIL) THEN
- err := AEDisposeDesc(selfAddr);
- END; (*IssueCreatePublisher*)
-
-
- FUNCTION PoseSizeDialog(VAR whatSize:longint):BOOLEAN;
-
- CONST kOK = 1;
- kCancel = 2;
- kOtherSize = 4;
- kOutlineItem = 5;
-
- VAR savedPort : GrafPtr;
- aDialog : DialogPtr;
- aString : STR255;
- theSize : LONGINT;
- itemHit : INTEGER;
-
- BEGIN
- GetPort(savedPort);
- aDialog := GetNewDialog(1004, nil, Pointer(-1));
- ShowWindow(aDialog);
- SetPort(aDialog);
-
- AdornDefaultButton(aDialog, kOutlineItem);
-
- {set the edittext button to contain the right size}
- NumToString(whatSize, aString);
- SetText(aDialog, kOtherSize, aString);
-
- REPEAT
- ModalDialog(nil, itemHit);
- UNTIL ((itemHit = kOK) OR
- (itemHit = kCancel));
-
- IF itemHit = kOK THEN
- RetrieveText(aDialog, KOtherSize, aString);
-
- DisposDialog(aDialog);
- SetPort(savedPort);
-
- IF (itemHit = kOK) THEN
- BEGIN
- {set the new size of the text}
- StringToNum(aString, whatSize);
- IF (whatSize<1) OR
- (whatSize>2000) THEN
- whatSize := 12;
- END;
- PoseSizeDialog := (itemHit = kOK);
- END;
-
- PROCEDURE IssueSizeCommand(theDocument:DPtr;theItem:INTEGER);
- VAR name : Str255;
- sizeDesc : AEDesc;
- theAddress : AEAddressDesc;
- err : OSErr;
- selTextObj : AEDesc;
-
- (*
- Vars to do with menu processing
- *)
- lastSize : INTEGER;
- upItem : INTEGER;
- downItem : INTEGER;
- otherItem : INTEGER;
- theSize : longint;
- theStyle : TextStyle;
- lineHeight : INTEGER;
- fontAscent : INTEGER;
-
- BEGIN
- err := MakeSelfAddress(theAddress);
-
- err := MakeSelectedTextObj(theDocument^.theWindow, theDocument^.theText, selTextObj);
-
- {check IF the item is on the Size menu}
- {remembering that we can add and delete items from it}
- lastSize := CountMItems(myMenus[sizeM]) - 5;
- upItem := lastSize + 2;
- downItem := upItem + 1;
- otherItem := downItem + 2;
-
- TEGetStyle(theDocument^.theText^^.selStart, theStyle, lineHeight, fontAscent, theDocument^.theText);
-
- GetItem(myMenus[sizeM], theItem, name);
-
- IF theItem <= lastSize THEN
- BEGIN
- GetItem(myMenus[sizeM], theItem, name);
- StringToNum(name, theSize);
- END
- ELSE
- IF theItem = upItem THEN
- theSize := theStyle.tsSize+1
- ELSE
- IF theItem = downItem THEN
- theSize := theStyle.tsSize-1
- ELSE
- If (theItem = otherItem) THEN
- BEGIN
- theSize := theStyle.tsSize;
- IF NOT PoseSizeDialog(theSize) THEN
- Exit(IssueSizeCommand);
- END;
-
- IF (err=noErr) THEN
- err := CreateOffsetDescriptor(theSize, sizeDesc);
-
- IF (err=noErr) THEN
- err := SendAESetObjProp(selTextObj,
- pPointSize,
- sizeDesc,
- theAddress);
- END; (*IssueSizeCommand*)
-
- PROCEDURE IssueStyleCommand(theDocument:DPtr;theItem:INTEGER);
- VAR theFace : Style;
- err : OSErr;
- result : AEDesc;
- selfAddr : AEAddressDesc;
- selTextObj : AEDesc;
- theStyle : TextStyle;
- lineHeight : INTEGER;
- fontAscent : INTEGER;
-
- BEGIN
- TEGetStyle(theDocument^.theText^^.selStart, theStyle, lineHeight, fontAscent, theDocument^.theText);
-
- theFace := [];
- case theItem of
- cPlain : theFace := [];
- cBold : theFace := [bold];
- cItalic : theFace := [italic];
- cUnderLine : theFace := [underline];
- cOutline : theFace := [outline];
- cShadow : theFace := [shadow];
- cCondense : theFace := [condense];
- cExtEND : theFace := [extend];
- END;{of case}
-
- IF (theFace = []) THEN
- err := BuildTypeTextStylesDesc([], [bold,italic,underline,outline,shadow,condense,extend], result)
- ELSE
- IF (theFace * theStyle.tsFace)<>[] THEN
- err := BuildTypeTextStylesDesc([], theFace, result)
- ELSE
- err := BuildTypeTextStylesDesc(theFace, [], result);
-
- err := MakeSelfAddress(selfAddr);
-
- IF (err=noErr) THEN
- err := MakeSelectedTextObj(theDocument^.theWindow, theDocument^.theText, selTextObj);
-
- IF (err=noErr) THEN
- err := SendAESetObjProp(selTextObj,
- pTextStyles,
- result,
- selfAddr);
-
- END; (* IssueStyleCommand *)
-
- CONST
- ETX = $03; (* Enter key on keyboard or keypad *)
- BS = $08; (* Backspace key on keyboard *)
- HT = $09; (* Tab key on keyboard *)
- CR = $0D; (* Return key on keyboard *)
- ESC = $1B; (* Clear key on keypad *)
- FS = $1C; (* Left arrow key on keypad *)
- GS = $1D; (* Right arrow key on keypad *)
- RS = $1E; (* Up arrow key on keypad *)
- US = $1F; (* Down arrow key on keypad *)
-
- FUNCTION IssueSetDataObjToBufferContents(VAR theObj:AEDesc):OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- theAddress : AEAddressDesc;
- myAppleEvent: AppleEvent;
- defReply : AppleEvent;
-
- BEGIN
- myErr := MakeSelfAddress(theAddress);
-
- (* create event *)
-
- IF (myErr=noErr) THEN
- myErr:= AECreateAppleEvent(kAECoreSuite,
- kAESetData,
- theAddress,
- 0,
- 0,
- myAppleEvent);
-
- (* add prop obj spec to the event *)
-
- if (myErr=noErr) THEN
- myErr:= AEPutParamDesc(myAppleEvent, keyDirectObject, theObj);
-
- (* add prop data to the event *)
-
- if (myErr=noErr) THEN
- myErr:= AEPutParamPtr(myAppleEvent,
- keyAEData,
- typeChar,
- Ptr(gTypingBuffer),
- gCharsInBuffer);
-
- (* send event *)
-
- (* only send the event if recording is implemented, otherwise the event will *)
- (* be sent twice *)
-
- if (gRecordingImplemented = TRUE) THEN
- if (myErr=noErr) THEN
- myErr:= AESend(myAppleEvent,
- defReply,
- kAENoReply+kAEDontExecute,
- kAENormalPriority,
- kAEDefaultTimeout,
- nil,
- nil);
-
- if (theAddress.dataHandle<>NIL) THEN
- ignoreErr:= AEDisposeDesc(theAddress);
-
- IF (myAppleEvent.dataHandle<>NIL) THEN
- ignoreErr:= AEDisposeDesc(myAppleEvent);
-
- IssueSetDataObjToBufferContents := myErr;
- END;
-
- PROCEDURE AddKeyToTypingBuffer(theDocument : DPtr;theKey : CHAR);
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
-
- BEGIN
- IF ((theKey=CHR(BS)) OR
- (theKey=CHR(FS)) OR
- (theKey=CHR(GS)) OR
- (theKey=CHR(RS)) OR
- (theKey=CHR(US))) THEN
- BEGIN
- FlushAndRecordTypingBuffer;
- IF (theKey=CHR(BS)) THEN
- BEGIN
- IF (theDocument^.theText^^.selStart<>theDocument^.theText^^.selEnd) THEN
- BEGIN
- myErr:= MakeTextObj(theDocument^.theWindow,
- theDocument^.theText^^.selStart,
- theDocument^.theText^^.selEnd,
- gTypingTargetObject);
- END
- ELSE
- BEGIN
- myErr:= MakeTextObj(theDocument^.theWindow,
- theDocument^.theText^^.selStart-1,
- theDocument^.theText^^.selStart,
- gTypingTargetObject);
- END;
-
- myErr := IssueSetDataObjToBufferContents(gTypingTargetObject);
-
- ignoreErr := AEDisposeDesc(gTypingTargetObject);
-
- gTypingTargetObject.dataHandle := nil;
- END
- END
- ELSE
- BEGIN
- IF (gCharsInBuffer=0) THEN
- myErr:= MakeSelectedTextObj(theDocument^.theWindow,
- theDocument^.theText,
- gTypingTargetObject);
-
- gTypingBuffer^[gCharsInBuffer] := theKey;
- gCharsInBuffer := gCharsInBuffer +1;
- END;
- END;
-
- PROCEDURE FlushAndRecordTypingBuffer;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
-
- BEGIN
- IF (gCharsInBuffer <> 0) THEN
- BEGIN
- myErr:= IssueSetDataObjToBufferContents(gTypingTargetObject);
-
- IF (gTypingTargetObject.dataHandle<>NIL) THEN
- ignoreErr:= AEDisposeDesc(gTypingTargetObject);
- END;
-
- gCharsInBuffer:= 0;
- gTypingTargetObject.dataHandle:= nil;
- END;
-
-
- {*****************************************************************************}
- {
- Object Accessors
- }
-
- FUNCTION WindowFromNullAccessor(wantClass : DescType;
- container : AEDesc;
- containerClass: DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LongInt): OSErr;
-
- VAR myErr : OSErr;
- actSize : Size;
- nameStr : Str255;
- theWindow : WindowToken;
- index : INTEGER;
- resultDesc : AEDesc;
-
- BEGIN
- myErr := -1708; { or whatever }
- value.dataHandle := nil;
- resultDesc.dataHandle := nil;
-
- {
- should only be called with wantClass = cWindow and
- with containerClass = typeNull or typeMyAppl.
- Currently accept as either formName or formAbsolutePosition
- }
-
- IF (wantClass <> cWindow) OR
- ((containerClass <> typeNull) AND (containerClass <> typeMyAppl)) OR
- NOT ((form = formName) OR (form = formAbsolutePosition)) THEN
- BEGIN
- WindowFromNullAccessor:=errAEWrongDataType;
- Exit(WindowFromNullAccessor);
- END;
-
- IF (form = formName) THEN
- BEGIN
- myErr := GetPStringFromDescriptor(selectionData, nameStr);
- theWindow := WindowNameToWindowPtr(@nameStr);
- END;
-
- IF (form = formAbsolutePosition) THEN
- BEGIN
- myErr := GetIntegerFromDescriptor(selectionData, index);
- theWindow := GetWindowPtrOfNthWindow(index);
- END;
-
- IF (myErr = noErr) THEN
- myErr := AECreateDesc(typeMyWndw,@theWindow,SizeOf(theWindow),value);
-
- WindowFromNullAccessor := myErr;
- END; { WindowFromNullAccessor }
-
- FUNCTION ApplicationFromNullAccessor(wantClass : DescType;
- container : AEDesc;
- containerClass : DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LongInt): OSErr;
-
- VAR myErr : OSErr;
- actSize : Size;
- nameStr : Str255;
- theApp : appToken;
- index : INTEGER;
- resultDesc : AEDesc;
-
- BEGIN
- value.dataHandle := nil;
- resultDesc.dataHandle := nil;
-
- {
- should only be called with wantClass = cWindow and
- with containerClass = typeNull.
- Currently accept as either formName or formAbsolutePosition
- }
-
- IF (wantClass <> cApplication) OR (containerClass <> typeNull) OR
- NOT ((form = formName) OR (form = formAbsolutePosition)) THEN
- BEGIN
- ApplicationFromNullAccessor:=errAEWrongDataType;
- Exit(ApplicationFromNullAccessor);
- END;
-
- IF (form = formName) OR (form = formAbsolutePosition) THEN
- BEGIN
- (* Don't care about data how specified - it's this app *)
- theApp.highLongOfPSN := 0;
- theApp.lowLongOfPSN := kCurrentProcess;
- END;
-
- myErr := AECreateDesc(typeMyAppl,@theApp,SizeOf(theApp),value);
-
- ApplicationFromNullAccessor := myErr;
- END; { ApplicationFromNullAccessor}
-
- PROCEDURE MoveToNonSpace(VAR start:INTEGER; limit:INTEGER; myChars:CharsHandle);
- (*
- Treats space,comma, full stop, ; and : as space chars
- *)
- BEGIN
- WHILE (start<=limit) DO
- IF myChars^^[start] IN [' ',',','.',';',':',CHR(10),CHR(13)] THEN
- start := start+1
- ELSE
- Exit(MoveToNonSpace);
- END;
-
- PROCEDURE MoveToSpace(VAR start:INTEGER; limit:INTEGER; myChars:CharsHandle);
- (*
- Treats space,comma, full stop, ; and : as space chars
- *)
- BEGIN
- WHILE (start<=limit) DO
- IF NOT (myChars^^[start] IN [' ',',','.',';',':',CHR(10),CHR(13)]) THEN
- start := start+1
- ELSE
- Exit(MoveToSpace);
- END;
-
- FUNCTION CountWords(inTextHandle:TEHandle; startAt:INTEGER; forHowManyChars:INTEGER):INTEGER;
- VAR myChars : CharsHandle;
- start : INTEGER;
- limit : INTEGER;
- myWords : INTEGER;
-
- BEGIN
- myChars := CharsHandle(inTextHandle^^.hText);
- limit := startAt+forHowManyChars-1;
- start := startAt;
- myWords := 0;
- MoveToNonSpace(start, limit, myChars);
- WHILE (start<=limit) DO
- BEGIN
- myWords := myWords+1;
- MoveToSpace(start, limit, myChars);
- MoveToNonSpace(start, limit, myChars);
- END;
- CountWords := myWords;
- END; (* CountWords *)
-
- PROCEDURE GetNthWordInfo(whichWord : INTEGER;
- inTextHandle : TEHandle;
- VAR wordStartChar : INTEGER;
- VAR wordLength : INTEGER);
- (*
- On entry: wordStartChar is start of char range to count in
- wordLength is number of chars to consider
-
- On Exit : wordStartChar is start of requested word
- wordLength is number of chars in word
- *)
- VAR myChars : CharsHandle;
- start : INTEGER;
- limit : INTEGER;
-
- BEGIN
- myChars := CharsHandle(inTextHandle^^.hText);
- limit := wordStartChar+wordLength-1;
- start := wordStartChar;
- MoveToNonSpace(start, limit, myChars);
- WHILE (start<=limit) AND (whichWord>0) DO
- BEGIN
- whichWord := whichWord-1;
- wordStartChar := start;
- MoveToSpace(start, limit, myChars);
- wordLength := start-wordStartChar;
-
- MoveToNonSpace(start, limit, myChars);
- END;
- END;(* GetNthWordInfo *)
-
- PROCEDURE GetWordInfo(whichWord : INTEGER;
- inTextHandle : TEHandle;
- VAR wordStartChar : INTEGER;
- VAR wordLength : INTEGER);
- (*
- On entry: wordStartChar is start of char range to count in
- wordLength is number of chars to consider
-
- On Exit : wordStartChar is start of requested word
- wordLength is number of chars in word
- *)
- VAR noOfWords : INTEGER;
-
- BEGIN
- noOfWords := CountWords(inTextHandle, wordStartChar, wordLength);
-
- IF (whichWord<0) THEN
- whichWord := noOfWords + whichWord +1;
-
- IF (whichWord>noOfWords) THEN
- BEGIN
- wordStartChar := wordStartChar+wordLength;
- wordLength := 0;
- END
- ELSE
- GetNthWordInfo(whichWord, inTextHandle, wordStartChar, wordLength);
- END;
-
- FUNCTION CountLines(inTextHandle:TEHandle):INTEGER;
- BEGIN
- (*
- CountLines makes use of info in TERec
- *)
- CountLines := inTextHandle^^.nLines;
- END;
-
- FUNCTION LineOfOffset(theHTE:TEHandle; charOffset:INTEGER):INTEGER;
- VAR n : INTEGER;
-
- BEGIN
- n := theHTE^^.nLines;
-
- WHILE (theHTE^^.lineStarts[n-1]>charOffset) AND
- (n>0) DO
- n := n-1;
-
- LineOfOffset := n;
-
- END; (*LineOfOffset*)
-
- PROCEDURE GetLineInfo(whichLine : INTEGER;
- inTextHandle : TEHandle;
- VAR lineStartChar : INTEGER;
- VAR lineLength : INTEGER);
- VAR noOfLines : INTEGER;
- myChars : CharsHandle;
-
- lineOfStart : INTEGER;
- lineOfEnd : INTEGER;
-
- BEGIN
- lineOfStart := LineOfOffset(inTextHandle, lineStartChar);
- lineOfEnd := LineOfOffset(inTextHandle, lineStartChar+lineLength-1);
-
- myChars := CharsHandle(inTextHandle^^.hText);
- noOfLines := lineOfEnd - lineOfStart +1;
-
- IF (whichLine<0) THEN
- whichLine := noOfLines + whichLine + 1;
-
- noOfLines := CountLines(inTextHandle);
- whichLine := whichLine + lineOfStart - 1; (* convert offset relative to offset absolute *)
-
- (* End of addition *)
-
- IF (whichLine<=lineOfEnd) THEN
- BEGIN
- lineStartChar := inTextHandle^^.lineStarts[whichLine-1];
- IF (whichLine=noOfLines) THEN
- lineLength := inTextHandle^^.teLength
- ELSE
- lineLength := inTextHandle^^.lineStarts[whichLine];
-
- lineLength := lineLength-lineStartChar;
- (*
- Don't return CR
- *)
- IF (myChars^^[ lineStartChar+lineLength-1] = CHR(13)) THEN
- lineLength := lineLength-1;
- END
- ELSE
- BEGIN
- IF (whichLine<noOfLines) THEN
- lineStartChar := inTextHandle^^.lineStarts[whichLine] (* start of whichLine++ *)
- ELSE
- lineStartChar := inTextHandle^^.teLength;
-
- lineLength := 0;
- END;
- END; (* GetLineInfo *)
-
- FUNCTION TextElemFromWndwAccessor(wantClass : DescType;
- container : AEDesc ;
- containerClass: DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- theWindow : WindowToken;
- actSize : Size;
- index : LongInt;
- theTextToken : TextToken;
- selectionRecord : AERecord;
- startText : TextToken;
- stopText : TextToken;
- returnedType : DescType;
- windDesc : AEDesc;
- theHTE : TEHandle;
- theDocument : DPtr;
- wordStartChar : INTEGER;
- wordLength : INTEGER;
-
- BEGIN
- myErr := -1700; { or whatever }
-
- selectionRecord.dataHandle := NIL;
-
- { do some checking for robustness' sake }
-
- IF (containerClass <> cWindow) OR
- ((wantClass <> cChar) AND
- (wantClass <> cSpot) AND
- (wantClass <> cWord) AND
- (wantClass <> cLine) ) OR
- ((form<>formRange) AND (form<>formAbsolutePosition)) THEN
- BEGIN
- TextElemFromWndwAccessor := errAEWrongDataType;
- Exit(TextElemFromWndwAccessor);
- END;
-
- { let's get the window which contains the text element }
-
- myErr := AECoerceDesc(container, typeMyWndw, windDesc);
- GetRawDataFromDescriptor( windDesc,
- @theWindow,
- sizeOf(theWindow),
- actSize);
- myErr := AEDisposeDesc(windDesc);
-
- IF (theWindow=NIL) THEN
- myErr := errAEIllegalIndex
- ELSE
- BEGIN
-
- theTextToken.tokenWindow := theWindow;
-
- theDocument := DPtrFromWindowPtr(theTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- IF (form = formAbsolutePosition) THEN
- BEGIN
- myErr := GetLongIntFromDescriptor(selectionData, index);
-
- IF (wantClass=cSpot) THEN
- BEGIN
- IF (index<0) THEN
- theTextToken.tokenOffset := theHTE^^.teLength+index+2 (* Past last char *)
- ELSE
- theTextToken.tokenOffset := index;
-
- theTextToken.tokenLength := 0;
- END;
-
- IF (wantClass=cChar) THEN
- BEGIN
- IF (index<0) THEN
- theTextToken.tokenOffset := theHTE^^.teLength+index+1
- ELSE
- theTextToken.tokenOffset := index;
-
- theTextToken.tokenLength := 1;
- END;
-
- IF (wantClass=cWord) THEN
- BEGIN
- wordStartChar := 0;
- wordLength := theHTE^^.teLength;
- GetWordInfo(index, theHTE, wordStartChar, wordLength); (* zero based *)
- theTextToken.tokenOffset := wordStartChar+1;
- theTextToken.tokenLength := wordLength;
- END;
-
- IF (wantClass=cLine) THEN
- BEGIN
- wordStartChar := 0;
- wordLength := theHTE^^.teLength;
- GetLineInfo(index, theHTE, wordStartChar, wordLength); (* zero based *)
- theTextToken.tokenOffset := wordStartChar+1;
- theTextToken.tokenLength := wordLength;
- END;
- END; { of formAbsolutePosition }
-
- IF form = formRange THEN
- BEGIN
- { coerce the selection data into an AERecord }
-
- myErr := AECoerceDesc(selectionData,typeAERecord,selectionRecord);
-
- { get the start object as a text token -
- this will reenter this proc but as formAbsolutePosition via the coercion handler}
-
- myErr := AEGetKeyPtr(selectionRecord,
- keyAERangeStart,
- typeMyText,
- returnedType,
- @startText,
- SizeOf(startText),
- actSize);
-
- { now do the same for the stop object }
-
- IF (myErr=noErr) THEN
- myErr := AEGetKeyPtr(selectionRecord,
- keyAERangeStop,
- typeMyText,
- returnedType,
- @stopText,
- SizeOf(stopText),
- actSize);
-
- IF (myErr=noErr) THEN
- IF (theTextToken.tokenWindow <> stopText.tokenWindow) OR
- (theTextToken.tokenWindow <> startText.tokenWindow) THEN
- BEGIN
- myErr := errAECorruptData; { or whatever }
- END;
-
- theTextToken.tokenOffset := startText.tokenOffset;
- theTextToken.tokenLength := stopText.tokenOffset +
- stopText.tokenLength -
- startText.tokenOffset;
-
- IF (theTextToken.tokenLength<0) THEN
- myErr := errAECorruptData; { or whatever }
-
- IF AEDisposeDesc(selectionRecord)=noErr THEN;
-
- END; { of formRange }
- END;
-
- { return theTextToken in a descriptor }
-
- IF (myErr=noErr) THEN
- myErr := AECreateDesc(typeMyText,
- @theTextToken,
- SizeOf(theTextToken),
- value);
-
- TextElemFromWndwAccessor := myErr;
- END; { TextElemFromWndwAccessor }
-
- FUNCTION TextElemFromTextAccessor(wantClass : DescType;
- container : AEDesc;
- containerClass: DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- actSize : Size;
- index : LongInt;
- theTextToken : TextToken;
- selectionRecord : AERecord;
- startText : TextToken;
- stopText : TextToken;
- returnedType : DescType;
- textDesc : AEDesc;
- theHTE : TEHandle;
- wordStartChar : INTEGER;
- wordLength : INTEGER;
- theDocument : DPtr;
-
- BEGIN
- myErr := -1700; { or whatever }
-
- { do some checking for robustness' sake }
-
- IF ((wantClass <> cChar) AND
- (wantClass <> cSpot) AND
- (wantClass <> cLine) AND
- (wantClass <> cWord)) OR
- ((form <> formAbsolutePosition) AND (form <> formRange)) THEN
- BEGIN
- TextElemFromTextAccessor := errAEWrongDataType;
- Exit(TextElemFromTextAccessor);
- END;
-
- { let's get the src text }
- myErr := AECoerceDesc(container, typeMyText, textDesc);
- GetRawDataFromDescriptor( textDesc,
- @theTextToken,
- sizeOf(theTextToken),
- actSize);
-
- myErr := AEDisposeDesc(textDesc);
-
- theDocument := DPtrFromWindowPtr(theTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- IF (form = formAbsolutePosition) THEN
- BEGIN
- myErr := GetLongIntFromDescriptor(selectionData, index);
-
- IF (wantClass=cSpot) THEN
- BEGIN
- IF (index<0) THEN
- theTextToken.tokenOffset := theTextToken.tokenOffset+index + 1 + theTextToken.tokenLength
- ELSE
- theTextToken.tokenOffset := theTextToken.tokenOffset+index-1;
- theTextToken.tokenLength := 0;
- END;
-
- IF (wantClass=cChar) THEN
- BEGIN
- IF (index<0) THEN
- theTextToken.tokenOffset := theTextToken.tokenOffset+index + 1+theTextToken.tokenLength
- ELSE
- theTextToken.tokenOffset := theTextToken.tokenOffset+index-1;
- theTextToken.tokenLength := 1;
- END;
-
- IF (wantClass=cWord) THEN
- BEGIN
- wordStartChar := theTextToken.tokenOffset-1;
- wordLength := theTextToken.tokenLength;
-
- GetWordInfo(index, theHTE, wordStartChar, wordLength);(*zero based*)
-
- theTextToken.tokenOffset := wordStartChar+1;
- theTextToken.tokenLength := wordLength;
- END;
-
- IF (wantClass=cLine) THEN
- BEGIN
- wordStartChar := theTextToken.tokenOffset-1;
- wordLength := theTextToken.tokenLength;
-
- GetLineInfo(index, theHTE, wordStartChar, wordLength);
-
- theTextToken.tokenOffset := wordStartChar+1;
- theTextToken.tokenLength := wordLength;
- END;
-
- END; { of formAbsolutePosition }
-
-
- IF (form = formRange) THEN
- BEGIN
- { coerce the selection data into an AERecord }
-
- myErr := AECoerceDesc(selectionData,typeAERecord,selectionRecord);
-
- { get the start object as a text token -
- this will reenter this proc but as formAbsolutePosition via the coercion handler}
-
- myErr := AEGetKeyPtr(selectionRecord,
- keyAERangeStart,
- typeMyText,
- returnedType,
- @startText,
- SizeOf(startText),
- actSize);
-
- { now do the same for the stop object }
-
- IF (myErr=noErr) THEN
- myErr := AEGetKeyPtr(selectionRecord,
- keyAERangeStop,
- typeMyText,
- returnedType,
- @stopText,
- SizeOf(stopText),
- actSize);
-
- IF (myErr=noErr) THEN
- IF (theTextToken.tokenWindow <> stopText.tokenWindow) OR
- (theTextToken.tokenWindow <> startText.tokenWindow) THEN
- BEGIN
- myErr := errAECorruptData; { or whatever }
- END;
-
- theTextToken.tokenOffset := startText.tokenOffset;
- theTextToken.tokenLength := stopText.tokenOffset +
- stopText.tokenLength -
- startText.tokenOffset;
-
- myErr := AEDisposeDesc(selectionRecord);
- END; { of formRange }
-
- { return theTextToken in a descriptor }
-
- myErr := AECreateDesc(typeMyText,
- @theTextToken,
- SizeOf(theTextToken),
- value);
-
- TextElemFromTextAccessor := myErr;
- END; { TextElemFromTextAccessor }
-
- FUNCTION PropertyFromTextAccessor(wantClass : DescType;
- container : AEDesc ;
- containerClass : DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- theTextToken : TextToken;
- theProperty : DescType;
- textDesc : AEDesc;
- propDesc : AEDesc;
- actualSize : Size;
- myTextProp : TextPropToken;
-
- BEGIN
- value.dataHandle := nil;
- textDesc.dataHandle := nil;
- propDesc.dataHandle := nil;
-
- IF (wantClass <> cProperty) OR
- (form <> formPropertyID) THEN
- BEGIN
- PropertyFromTextAccessor:=errAEWrongDataType;
- Exit(PropertyFromTextAccessor);
- END;
-
- { get the text token }
- myErr := AECoerceDesc(container, typeMyText, textDesc);
- GetRawDataFromDescriptor( textDesc,
- @theTextToken,
- sizeOf(theTextToken),
- actualSize);
-
- { get the property }
- myErr := AECoerceDesc(selectionData, typeType, propDesc);
- GetRawDataFromDescriptor( propDesc,
- @theProperty,
- sizeOf(theProperty),
- actualSize);
- (*
- Combine the two into single token
- *)
- myTextProp.propertyTextToken := theTextToken;
- myTextProp.propertyProperty := theProperty;
-
- myErr := AECreateDesc(typeMyTextProp,
- @myTextProp,
- SizeOf(myTextProp),
- value);
-
- IF (textDesc.dataHandle<>nil) THEN
- DisposHandle(Handle(textDesc.dataHandle));
-
- IF (propDesc.dataHandle<>nil) THEN
- DisposHandle(Handle(propDesc.dataHandle));
-
- PropertyFromTextAccessor := myErr;
- END; { PropertyFromTextAccessor }
-
- FUNCTION PropertyFromWndwAccessor(wantClass : DescType;
- container : AEDesc ;
- containerClass : DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- theWindowToken: WindowToken;
- theProperty : DescType;
- windowDesc : AEDesc;
- propDesc : AEDesc;
- actualSize : Size;
- myWindowProp : WindowPropToken;
-
- BEGIN
- value.dataHandle := nil;
- windowDesc.dataHandle := nil;
- propDesc.dataHandle := nil;
-
- IF (wantClass <> cProperty) OR
- (form <> formPropertyID) THEN
- BEGIN
- PropertyFromWndwAccessor:=errAEWrongDataType;
- Exit(PropertyFromWndwAccessor);
- END;
-
- { get the window token - it's the container }
-
- myErr := AECoerceDesc(container, typeMyWndw, windowDesc);
- GetRawDataFromDescriptor( windowDesc,
- @theWindowToken,
- sizeOf(theWindowToken),
- actualSize);
-
- { Check the window exists }
-
- IF (theWindowToken=NIL) THEN
- myErr := errAEIllegalIndex
- ELSE
- BEGIN
-
- { get the property - it's in the selection data }
-
- myErr := AECoerceDesc(selectionData, typeType, propDesc);
- GetRawDataFromDescriptor( propDesc,
- @theProperty,
- sizeOf(theProperty),
- actualSize);
- (*
- Combine the two into single token
- *)
- myWindowProp.tokenWindowToken := theWindowToken;
- myWindowProp.tokenProperty := theProperty;
-
- myErr := AECreateDesc(typeMyWindowProp,
- @myWindowProp,
- SizeOf(myWindowProp),
- value);
- END;
-
- IF (windowDesc.dataHandle<>nil) THEN
- DisposHandle(Handle(windowDesc.dataHandle));
-
- IF (propDesc.dataHandle<>nil) THEN
- DisposHandle(Handle(propDesc.dataHandle));
-
- PropertyFromWndwAccessor := myErr;
- END; { PropertyFromWndwAccessor }
-
- FUNCTION PropertyFromApplAccessor(wantClass : DescType;
- container : AEDesc ;
- containerClass : DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LongInt): OSErr;
- VAR
- myErr : OSErr;
- theApplToken : AppToken;
- theProperty : DescType;
- applDesc : AEDesc;
- propDesc : AEDesc;
- actualSize : Size;
- myApplProp : ApplPropToken;
-
- BEGIN
- value.dataHandle := nil;
- applDesc.dataHandle := nil;
- propDesc.dataHandle := nil;
-
- IF (wantClass <> cProperty) OR
- (form <> formPropertyID) THEN
- BEGIN
- PropertyFromApplAccessor:=errAEWrongDataType;
- Exit(PropertyFromApplAccessor);
- END;
-
- { get the application token - it's the container }
-
- myErr := AECoerceDesc(container, typeMyAppl, applDesc);
- GetRawDataFromDescriptor( applDesc,
- @theApplToken,
- sizeOf(theApplToken),
- actualSize);
-
- { get the property - it's in the selection data }
-
- myErr := AECoerceDesc(selectionData, typeType, propDesc);
- GetRawDataFromDescriptor( propDesc,
- @theProperty,
- sizeOf(theProperty),
- actualSize);
- (*
- Combine the two into single token
- *)
- myApplProp.tokenApplToken := theApplToken;
- myApplProp.tokenApplProperty := theProperty;
-
- myErr := AECreateDesc(typeMyApplProp,
- @myApplProp,
- SizeOf(myApplProp),
- value);
-
- IF (applDesc.dataHandle<>nil) THEN
- DisposHandle(Handle(applDesc.dataHandle));
-
- IF (propDesc.dataHandle<>nil) THEN
- DisposHandle(Handle(propDesc.dataHandle));
-
- PropertyFromApplAccessor := myErr;
- END; { PropertyFromApplAccessor }
-
- FUNCTION MenuNameToMenuToken(theName:Str255;VAR theToken:MenuToken):OSErr;
- VAR
- index : INTEGER;
-
- BEGIN
- for index := appleM TO kLastMenu DO
- BEGIN
- IF (IUEqualString(theName, myMenus[index]^^.menuData)=0) THEN
- BEGIN
- theToken.theTokenMenu := myMenus[index];
- theToken.theTokenID := index+appleID;
-
- MenuNameToMenuToken := noErr;
- Exit(MenuNameToMenuToken);
- END;
- END;
- MenuNameToMenuToken := errAEIllegalIndex;
- END;
-
- FUNCTION MenuFromNullAccessor(wantClass : DescType;
- container : AEDesc;
- containerClass: DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LONGINT):OSErr;
- VAR
- myErr : OSErr;
- nameStr : Str255;
- theMenu : MenuToken;
- index : INTEGER;
- resultDesc : AEDesc;
-
- BEGIN
- myErr := errAEBadKeyForm; (* or whatever *)
-
- value.dataHandle := nil;
- resultDesc.dataHandle := nil;
-
- (*
- should only be called with wantClass = cMenu and
- with containerClass = typeNull or typeMyAppl.
- Currently accept as either formName or formAbsolutePosition
- *)
-
- if ((wantClass <> cMenu) OR
- ((containerClass <> typeNull) AND (containerClass <> typeMyAppl)) OR
- NOT((form = formName) OR (form = formAbsolutePosition))) THEN
- MenuFromNullAccessor:= errAEWrongDataType;
-
- IF (form = formName) THEN
- BEGIN
- myErr := GetPStringFromDescriptor(selectionData, nameStr);
- myErr := MenuNameToMenuToken(nameStr, theMenu);
- END;
-
- IF (form = formAbsolutePosition) THEN
- BEGIN
- myErr := GetIntegerFromDescriptor(selectionData, index);
- IF (index<0) THEN
- index := kLastMenu + index + 1;
-
- IF (index>0) AND (index<=kLastMenu+1) THEN
- BEGIN
- theMenu.theTokenMenu := myMenus[index-1];
- theMenu.theTokenID := index-1+appleID;
- END
- else
- myErr := errAEIllegalIndex; (* or whatever *)
- END;
-
- IF (myErr = noErr) THEN
- myErr := AECreateDesc(typeMyMenu, Ptr(@theMenu), sizeof(theMenu), value);
-
- MenuFromNullAccessor := myErr;
- END; (* MenuFromNullAccessor *)
-
- FUNCTION PropertyFromMenuAccessor(wantClass : DescType;
- container : AEDesc;
- containerClass : DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : LONGINT) : OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- theMenuToken: MenuToken;
- theProperty : DescType;
- menuDesc : AEDesc;
- propDesc : AEDesc;
- actualSize : Size;
- myMenuProp : MenuPropToken;
-
- BEGIN
- value.dataHandle := nil;
- menuDesc.dataHandle := nil;
- propDesc.dataHandle := nil;
-
- IF ((wantClass <> cProperty) OR
- (form <> formPropertyID)) THEN
- BEGIN
- PropertyFromMenuAccessor := errAEWrongDataType;
- Exit(PropertyFromMenuAccessor);
- END;
-
- (* get the menu token - it's the container *)
-
- myErr := AECoerceDesc(container, typeMyMenu, menuDesc);
- GetRawDataFromDescriptor(menuDesc,
- Ptr(@theMenuToken),
- sizeof(theMenuToken),
- actualSize);
-
- (* get the property - it's in the selection data *)
-
- myErr := AECoerceDesc(selectionData, typeType, propDesc);
- GetRawDataFromDescriptor(propDesc,
- Ptr(@theProperty),
- sizeof(theProperty),
- actualSize);
- (*
- Combine the two into single token
- *)
- myMenuProp.theMenuToken := theMenuToken;
- myMenuProp.theMenuProp := theProperty;
-
- myErr := AECreateDesc(typeMyMenuProp,
- Ptr(@myMenuProp),
- sizeof(myMenuProp),
- value);
-
- IF (menuDesc.dataHandle<>nil) THEN
- ignoreErr := AEDisposeDesc(menuDesc);
-
- IF (propDesc.dataHandle<>nil) THEN
- ignoreErr := AEDisposeDesc(propDesc);
-
- PropertyFromMenuAccessor := myErr;
- END; (* PropertyFromMenuAccessor *)
-
- FUNCTION PropertyFromMenuItemAccessor(wantClass : DescType;
- container : AEDesc;
- containerClass : DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : longint):OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- theMenuItemToken : MenuItemToken;
- theProperty : DescType;
- itemDesc : AEDesc;
- propDesc : AEDesc;
- actualSize : Size;
- myItemProp : MenuItemPropToken;
-
- BEGIN
- value.dataHandle := nil;
- itemDesc.dataHandle := nil;
- propDesc.dataHandle := nil;
-
- if ((wantClass <> cProperty) OR
- (form <> formPropertyID)) THEN
- BEGIN
- PropertyFromMenuItemAccessor := errAEWrongDataType;
- END;
-
- (* get the menu token - it's the container *)
-
- myErr := AECoerceDesc(container, typeMyMenuItem, itemDesc);
- GetRawDataFromDescriptor(itemDesc,
- Ptr(@theMenuItemToken),
- sizeof(theMenuItemToken),
- actualSize);
-
- (* get the property - it's in the selection data *)
-
- myErr := AECoerceDesc(selectionData, typeType, propDesc);
- GetRawDataFromDescriptor(propDesc,
- Ptr(@theProperty),
- sizeof(theProperty),
- actualSize);
- (*
- Combine the two into single token
- *)
- myItemProp.theItemToken := theMenuItemToken;
- myItemProp.theItemProp := theProperty;
-
- myErr := AECreateDesc(typeMyItemProp,
- Ptr(@myItemProp),
- sizeof(myItemProp),
- value);
-
- IF (itemDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(itemDesc);
-
- IF (propDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(propDesc);
-
- PropertyFromMenuItemAccessor := myErr;
- END; (* PropertyFromMenuItemAccessor *)
-
- FUNCTION ItemNameToItemIndex(theName:Str255; theMenu:MenuHandle; VAR theIndex: INTEGER):OSErr;
- VAR
- index : INTEGER;
- maxItems : INTEGER;
- menuName : Str255;
-
- BEGIN
- maxItems := CountMItems(theMenu);
-
- FOR index := 1 TO maxItems DO
- BEGIN
- GetItem(theMenu, index, menuName);
- IF (IUEqualString(theName, menuName)=0) THEN
- BEGIN
- theIndex := index;
- ItemNameToItemIndex := noErr;
- Exit(ItemNameToItemIndex);
- END;
- END;
- ItemNameToItemIndex := errAEIllegalIndex;
- END;
-
- FUNCTION MenuItemFromMenuAccessor(wantClass : DescType;
- container : AEDesc;
- containerClass : DescType;
- form : DescType;
- selectionData : AEDesc;
- VAR value : AEDesc;
- theRefCon : longint) : OSErr;
- VAR
- myErr : OSErr;
- ignoreErr : OSErr;
- theMenuItemToken : MenuItemToken;
- theMenuToken : MenuToken;
- menuDesc : AEDesc;
- actualSize : Size;
- nameStr : Str255;
- maxItems : INTEGER;
- index : INTEGER;
-
- BEGIN
- value.dataHandle := nil;
- menuDesc.dataHandle := nil;
-
- IF ((wantClass <> cMenuItem) OR
- (containerClass <> cMenu) OR
- ((form <> formAbsolutePosition) AND (form <> formName))) THEN
- BEGIN
- MenuItemFromMenuAccessor := errAEWrongDataType;
- Exit(MenuItemFromMenuAccessor);
- END;
-
- (* get the menu token - it's the container *)
-
- myErr := AECoerceDesc(container, typeMyMenu, menuDesc);
- GetRawDataFromDescriptor(menuDesc,
- Ptr(@theMenuToken),
- sizeof(theMenuToken),
- actualSize);
-
- IF (form=formAbsolutePosition) THEN
- BEGIN
- myErr := GetIntegerFromDescriptor(selectionData, index);
- maxItems := CountMItems(theMenuToken.theTokenMenu);
-
- IF (index<0) THEN
- index := maxItems + index + 1;
-
- IF ((index<1) OR (index>maxItems)) THEN
- myErr := errAEIllegalIndex;
- END;
-
- if (form = formName) THEN
- BEGIN
- myErr := GetPStringFromDescriptor(selectionData, nameStr);
- myErr := ItemNameToItemIndex(nameStr, theMenuToken.theTokenMenu, index);
- END;
-
- (*
- Combine the two into single token
- *)
-
- theMenuItemToken.theMenuToken := theMenuToken;
- theMenuItemToken.theTokenItem := index;
-
- IF (myErr=noErr) THEN
- myErr := AECreateDesc(typeMyMenuItem,
- Ptr(@theMenuItemToken),
- sizeof(theMenuItemToken),
- value);
-
- IF (menuDesc.dataHandle<>NIL) THEN
- ignoreErr := AEDisposeDesc(menuDesc);
-
- MenuItemFromMenuAccessor := myErr;
- END; (* MenuItemFromMenuAccessor *)
-
- {*****************************************************************************}
- {
- Stuff for counting objects
- }
-
- FUNCTION MyCountProc( desiredType : DescType;
- containerClass: DescType;
- container : AEDesc;
- VAR result : LongInt): OSErr;
-
- { so far all I count is:
- (1) the number of active windows in the app;
- (2) the number of words in a window
- }
-
- VAR myErr : OSErr;
- theWindowToken : WindowToken;
- theDocument : DPtr;
- theHTE : TEHandle;
- newDesc : AEDesc;
- wordStart : INTEGER;
- wordLength : INTEGER;
- tokenSize : Size;
- theTextToken : TextToken;
-
- BEGIN
- result := -1; { easily recognized illegal value }
-
- myErr := errAEWrongDataType;
-
- IF (desiredType = cWindow) THEN
- BEGIN
- IF (containerClass = typeNull) OR
- (containerClass = cApplication) THEN
- result := CountWindows;
- END;
-
- IF (desiredType = cWord) OR
- (desiredType = cLine) OR
- (desiredType = cChar) THEN
- BEGIN
- myErr := AECoerceDesc(container, typeMyWndw, newDesc);
- IF (newDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor(newDesc,
- @theWindowToken,
- SizeOf(theWindowToken),
- tokenSize);
-
- myErr := AEDisposeDesc(newDesc);
-
- IF (theWindowToken=NIL) THEN
- myErr := errAEIllegalIndex
- ELSE
- BEGIN
-
- theDocument := DPtrFromWindowPtr(theWindowToken);
- theHTE := theDocument^.theText;
-
- IF (desiredType = cWord) THEN
- BEGIN
- wordStart := 0;
- wordLength := theHTE^^.teLength;
- result := CountWords(theHTE, wordStart, wordLength);
- END;
-
- IF (desiredType = cChar) THEN
- result := theHTE^^.teLength;
-
- IF (desiredType = cLine) THEN
- result := CountLines(theHTE);
-
- END;
- END;
-
- myErr := AECoerceDesc(container, typeMyText, newDesc);
- IF (newDesc.descriptorType<>typeNull) THEN
- BEGIN
- GetRawDataFromDescriptor( newDesc,
- @theTextToken,
- sizeOf(theTextToken),
- tokenSize);
-
- myErr := AEDisposeDesc(newDesc);
-
- theDocument := DPtrFromWindowPtr(theTextToken.tokenWindow);
- theHTE := theDocument^.theText;
-
- IF (desiredType = cWord) THEN
- BEGIN
- wordStart := theTextToken.tokenOffset-1;
- wordLength := theTextToken.tokenLength;
- result := CountWords(theHTE, wordStart, wordLength);
- END;
-
- IF (desiredType = cChar) THEN
- result := theTextToken.tokenLength;
-
- IF (desiredType = cLine) THEN
- result:= LineOfOffset(theHTE,theTextToken.tokenOffset-1) -
- LineOfOffset(theHTE,theTextToken.tokenOffset+theTextToken.tokenLength-1)
- +1;
- END;
-
- END;
-
- MyCountProc := myErr;
- END; { MyCountProc }
-
- {*****************************************************************************}
- {
- Coercion Handlers - Allow AEResolve to do the hard work
- }
- FUNCTION CoerceObjToAnything(theAEDesc : AEDesc;
- toType : DescType;
- handlerRefCon: LongInt;
- VAR result : AEDesc): OSErr;
- {
- CoerceObjToAnything functions by using AEResolve to do the hard
- work.
- }
- CONST kAEIDoMinimum = 0;
-
- VAR myErr : OSErr;
- objDesc : AEDesc;
-
- BEGIN
- myErr := errAECoercionFail;
-
- result.dataHandle := NIL;
- objDesc.dataHandle := NIL;
-
-
- IF (theAEDesc.descriptorType <> typeObjectSpecifier) THEN
- BEGIN
- CoerceObjToAnything := errAEWrongDataType;
- Exit(CoerceObjToAnything);
- END;
-
- { resolve the object specifier }
- myErr := AEResolve(theAEDesc,kAEIDoMinimum,objDesc);
-
- { hopefully it's the right type by now, but we'll give it a nudge }
- IF (myErr=noErr) THEN
- BEGIN
- myErr := AECoerceDesc(objDesc,toType,result);
- myErr := AEDisposeDesc(objDesc);
- END;
-
- IF (result.descriptorType<>toType) THEN
- BEGIN
- {DebugStr('COTA - Not of requested type');}
- END;
-
- CoerceObjToAnything := myErr;
- END; { CoerceObjToAnything }
-
- {*****************************************************************************}
-
- {----------------------------------------------------------------------------------------------}
-
- {now for the edition manager event handling code}
-
- FUNCTION GetHandleFromEvent(theAppleEvent : AppleEvent; VAR sectionH : SectionHandle):OSErr;
-
- VAR ignoreType : DescType;
- ignoreSize : Size;
-
- BEGIN
- GetHandleFromEvent := AEGetKeyPtr(theAppleEvent, keyDirectObject, typeSectionH,
- ignoreType, @sectionH, SizeOf(sectionHandle), ignoreSize);
- END;
-
- {----------------------------------------------------------------------------------------------}
- FUNCTION DoReadSection(theAppleEvent, reply : AppleEvent; refCon : LONGINT): OSErr;
-
- VAR err : OSErr;
- sectionH : SectionHandle;
-
- BEGIN
- err := GetHandleFromEvent(theAppleEvent, sectionH);
- IF IsRegisteredSection(sectionH) = noErr THEN
- ReadAnEdition(sectionH);
- DoReadSection := err;
- END;
-
- {----------------------------------------------------------------------------------------------}
- FUNCTION DoWriteSection(theAppleEvent, reply : AppleEvent; refCon : LONGINT): OSErr;
-
- VAR err : OSErr;
- sectionH : SectionHandle;
-
- BEGIN
- err := GetHandleFromEvent(theAppleEvent, sectionH);
- IF IsRegisteredSection(sectionH) = noErr THEN
- WriteAnEdition(sectionH);
- DoWriteSection := err;
-
- END;
-
- {----------------------------------------------------------------------------------------------}
- FUNCTION DoScrollSection(theAppleEvent, reply : AppleEvent; refCon : LONGINT): OSErr;
-
- VAR err : OSErr;
- sectionH : SectionHandle;
- aSectHandle : SectHandle;
-
- BEGIN
- err := GetHandleFromEvent(theAppleEvent, sectionH);
- {get at the sectHandle}
- aSectHandle := SectHandle(GetERefCon(sectionH));
- TESetSelect(aSectHandle^^.fStart, aSectHandle^^.fEnd, aSectHandle^^.fDocument^.theText);
- ShowSelect(aSectHandle^^.fDocument);
- DoScrollSection := err;
- END;
-
- {----------------------------------------------------------------------------------------------}
- FUNCTION DoCancelSection(theAppleEvent, reply : AppleEvent; refCon : LONGINT): OSErr;
-
- VAR err : OSErr;
- sectionH : SectionHandle;
- aSectHandle : SectHandle;
-
- BEGIN
- err := GetHandleFromEvent(theAppleEvent, sectionH);
- aSectHandle := SectHandle(GetERefCon(sectionH));
- err := UnRegisterSection(sectionH);
- DeleteASection(aSectHandle, aSectHandle^^.fDocument);
- DoCancelSection := noErr;
- END;
-
- { -----------------------------------------------------------------------
- Name: InitAppleEvents
- Purpose: Initialise the AppleEvent despatch table
- -----------------------------------------------------------------------*}
-
- {$S Main}
- PROCEDURE InitAppleEvents;
-
- CONST noRefCon = -1;
- VAR
- aevtErr: OSErr ;
- BEGIN
- gBigBrother := 0;
- gCharsInBuffer := 0;
- gTypingBuffer := typingBufPtr(NewPtr(32000));
- gTypingTargetObject.dataHandle := NIL;
-
-
- {set up the despatch table for the four standard apple events}
-
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEOpenApplication, @DoOpenApp, noRefCon, FALSE) ;
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, @DoOpenDocument, noRefCon, FALSE) ;
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments, @DoPrintDocuments, noRefCon, FALSE) ;
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, @MyQuit, noRefCon, FALSE) ;
-
- { set up the despatch table for the core AppleEvents for text }
-
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAEDelete, @DoDeleteEdit,noRefCon, FALSE);
-
- aevtErr := AEInstallEventHandler( kAEMiscStandards, kAECut, @DoCutEdit, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAEMiscStandards, kAECopy, @DoCopyEdit, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAEMiscStandards, kAEPaste, @DoPasteEdit, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAESetData,@DoSetData, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAEGetData,@DoGetData, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAEGetDataSize,@DoGetDataSize, noRefCon, FALSE);
-
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAECountElements, @HandleNumberOfElements, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAECreateElement, @DoNewElement, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAEDoObjectsExist, @DoIsThereA, noRefCon, FALSE);
-
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAEClose, @DoCloseWindow,noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAECoreSuite, kAESave, @DoSaveWindow,noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAEMiscStandards, kAERevert, @DoRevertWindow,noRefCon, FALSE);
-
- aevtErr := AEInstallEventHandler( kAEMiscStandards, kAECreatePublisher, @HandleCreatePub, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kAEMiscStandards, kAEMakeObjectsVisible, @HandleShowSelection, noRefCon, FALSE);
-
- { Now look for recording notifications }
-
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEStartedRecording, @HandleStartRecording, noRefCon, FALSE);
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEStoppedRecording, @HandleStopRecording, noRefCon, FALSE);
-
- { Now Put in the required object accessors }
-
- aevtErr := AESetObjectCallbacks(NIL,@MyCountProc,NIL,NIL,NIL,NIL,NIL);
-
- aevtErr := AEInstallObjectAccessor(cWindow, typeNull, @WindowFromNullAccessor, 0,FALSE);
- aevtErr := AEInstallObjectAccessor(cWindow, typeMyAppl, @WindowFromNullAccessor, 0,FALSE);
- aevtErr := AEInstallObjectAccessor(cApplication, typeNull, @ApplicationFromNullAccessor, 0,FALSE);
- aevtErr := AEInstallObjectAccessor(cProperty, typeMyAppl, @PropertyFromApplAccessor,0,FALSE);
-
- aevtErr := AEInstallObjectAccessor(cChar, typeMyWndw,@TextElemFromWndwAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cSpot, typeMyWndw,@TextElemFromWndwAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cWord, typeMyWndw,@TextElemFromWndwAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cLine, typeMyWndw,@TextElemFromWndwAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cSelection, typeMyWndw,@TextElemFromWndwAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cProperty, typeMyWndw,@PropertyFromWndwAccessor,0,FALSE);
-
- aevtErr := AEInstallObjectAccessor(cProperty, typeMyText,@PropertyFromTextAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cChar, typeMyText,@TextElemFromTextAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cWord, typeMyText,@TextElemFromTextAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cLine, typeMyText,@TextElemFromTextAccessor,0,FALSE);
- aevtErr := AEInstallObjectAccessor(cSpot, typeMyText,@TextElemFromTextAccessor,0,FALSE);
-
- aevtErr := AEInstallObjectAccessor(cMenu, typeNull, @MenuFromNullAccessor, 0,false);
- aevtErr := AEInstallObjectAccessor(cProperty, typeMyMenu, @PropertyFromMenuAccessor,0,false);
- aevtErr := AEInstallObjectAccessor(cProperty, typeMyMenuItem, @PropertyFromMenuItemAccessor,0,false);
- aevtErr := AEInstallObjectAccessor(cMenuItem, typeMyMenu, @MenuItemFromMenuAccessor,0,false);
- { Now the coercion handlers }
-
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyAppl, @CoerceObjToAnything,0,TRUE,FALSE);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyWndw, @CoerceObjToAnything,0,TRUE,FALSE);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyText, @CoerceObjToAnything,0,TRUE,FALSE);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyTextProp, @CoerceObjToAnything,0,TRUE,FALSE);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyWindowProp,@CoerceObjToAnything,0,TRUE,FALSE);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyApplProp, @CoerceObjToAnything,0,TRUE,FALSE);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyMenu, @CoerceObjToAnything,0,true,false);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyMenuProp, @CoerceObjToAnything,0,true,false);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyMenuItem, @CoerceObjToAnything,0,true,false);
- aevtErr := AEInstallCoercionHandler(typeObjectSpecifier,typeMyItemProp, @CoerceObjToAnything,0,true,false);
- {now install the appropriate edition manager events}
-
- aevtErr := AEInstallEventHandler( sectionEventmsgClass, sectionReadMsgID, @DoReadSection, noRefCon, FALSE) ;
- aevtErr := AEInstallEventHandler( sectionEventmsgClass, sectionWriteMsgID, @DoWriteSection, noRefCon, FALSE) ;
- aevtErr := AEInstallEventHandler( sectionEventmsgClass, sectionScrollMsgID, @DoScrollSection, noRefCon, FALSE) ;
- aevtErr := AEInstallEventHandler( sectionEventmsgClass, sectionCancelMsgID, @DoCancelSection, noRefCon, FALSE) ;
-
- END;
-
-
- END.
-